: This article mainly introduces the application of Nginx server load balancer in Jinshan Xiaoyao network N years ago. if you are interested in PHP tutorials, refer to it. In Kingsoft Xiaoyao network, the front-end server load balancer uses Nginx. The two Nginx servers are in a group and undertake various types of server load balancer services. The two server load balancer servers are active, each server is bound with a public IP address as the server load balancer server. when one of them fails, the other server takes over the virtual IP address of the faulty server. The nginx. conf configuration code is as follows:
Code:
User www; work_processes 8; error_log/data1/logs/nginx_error.log crit; pid/usr/local/webserver/nginx. pid; # specifies the value for maximum file descriptors that can be opened by this process worker_rlimit_nofile 51200 events {use epoll; worker_connections 51200;} http {include mine. types; default_type application/octet-strem; # charset UTF-8 limit 128 k; limit 32 k; limit 432 k; sendfile on; # tcp_nopush on; keepalive_timeout 30; tcp_nodelay on; fastcgi_connect_timeout 300; limit 300; fastcgi_read_timeout 300; limit 64 k; fastcgi_buffers 464 k; limit 128 k; limit 128 k; gzip on; gzip_min_length 1 k; gzip_buffers 416 k; gzip_http_version 1.1 gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; limit_zone anti_attack $ binary_remote_addr10m; # client_max_body_size 300 m; # The maximum number of bytes of the buffer proxy buffer client can be understood as the client_body_size 128 k to be passed to the local user; # timeout time for connection to the backend server _ timeout time for initiating a handshake and waiting for response proxy_connect_time 600; # After the connection is successful _ wait for the response time of the backend server _ in fact, the party that has already entered the backend is waiting for processing proxy_read_timeout 600; # backend return time _ pass all data within the specified time proxy_send_timeout 600; # In the proxy request cache, the user's header information is saved for Nginx rule processing. proxy_buffer_size 16 k; proxy_buffers 432 k; proxy_busy_buffers_size 64 k; proxy_temp_file_write_size 64 k; # cache proxy_temp_path/data2/proxy_temp_path; proxy_cache_path/data2/proxy_cache_path levels = keys_z> 200 m inactive = 1d max_size = 5; upstream myserver_pool {server xx. xx. xx.1: 80 weight = 1 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.2: 80 weight = 1 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.3: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;} upstream php_server_pool {server xx. xx. xx.4: 80 weight = 1 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.5: 80 weight = 1 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.6: 80 weight = 1 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.7: 80 weight = 1 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.8: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;} upstream bbs_server_pool {ip = hash; server xx. xx. xx.9: 80 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.10: 80 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.11: 80 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.12: 80 max_fails = 2 fail_timeout = 30 s;} upstream cms_server_pool {server xx. xx. xx.13: 80 weight = 1 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.14: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;} upstream pic_server_pool {server xx. xx. xx.15: 80 weight = 1 max_fails = 2 fail_timeout = 30 s; server xx. xx. xx.16: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;} upstream xoyohimsg_server_pool {server xx. xx. xx.17: 3245; server xx. xx. xx.18: 3245 down;} # transfer the xoyo.com domain name to www.xoyo.com server {listen 80; server_name xiyo.com; rewrite ^ /(. *) http: xoyo.com/permanent; acces_log/data1/logs/xoyo.com _ access. log ;}# User Center HTTP/SSL encrypted browsing server {listen 443; server_name my.xoyo.com ssl on; ssl_cretificate my.xoyo.com. crt; ssl_cretificate_key my.xoyo.com. key; location/{proxy_pass http://php_server_pool ; Proxy_set_header Host my.xoyo.com; proxy_set_header X-Forward-For $ remote_addr;} access_log/data1/logs/my.xoyo.com _ access. log ;}# image server, access different backend servers in different paths {listen 80; server_name pic.xoyo.com; location/cms/{proxy_pass http://cms_server_pool ; Proxy_set_header Host pic.xoyo.com; proxy_set_header X-Forward-For $ remote_addr;} access_log/data1/logs/pic.xoyo.com _ access. log ;}# download audio station file for simple anti-Leech # limit_zone media % binary_remote_addr 10 m; server {listen 80; server_name media.xoyo.com; location/{proxy_pass http://cms_server_pool ; Protected Host $ host; protected X-Forward-For $ remote_addr; valid_reference nine blocked www.xoyo.com * using www.kingsoft.com * .kingsoft.com www.kingsoft.cn * .kingsoft.cn; if ($ response) {rewrite ^/ http://www.xoyo.com ;}} Access_log/data1/logs/media.xoyo.com _ access. log ;}# server load balancer of WebIM, two types of HTTP server {listen 80; server_name hi.xoyo.com; # reverse proxy a custom-developed high-performance message queue HTTP server location/recmessage. xoyo {proxy_pass http://xoyohimsg_server_pool ; Proxy_set_header Host $ host;} location/{proxy_pass http://php_server_pool ; Proxy_set_header Host $ host; proxy_set_header X-Forward-For $ remote_addr;} access_log/data1/logs/hi.xoyo.com _ access. log; # conduct Web cache server {listen 80; server_name bbs.xoyo.com * .bbs.xoyo.com bbs.xoyo.kingsoft.com; location/{proxy_pass for images, Flash, JavaScript, CSS, and static HTML http://bbs_server_pool ; Proxy_set_header Host $ host; proxy_set_header X-Forward-For $ remote_addr;} location ~. *\. (Gif | jpg | jpeg | png | bmp | swf | js | css | html | shtml) $ {proxy_cache cache_one; proxy_cache_valid 20010 m; proxy_cache_valid 3041 m; proxy_cache_valid 301302 ih; proxy_cache_valid any 1 m; proxy_cache_key $ host $ uri $ is_args $ args; proxy_set_header Host $ host; proxy_set_header X-Forward-For $ remote_addr; proxy_pass http://bbs_server_pool ;} Log_format bbs '$ remote_addr $ host $ remote_user [$ time_local] "$ request" ''" $ status "$ response" $ http_referer "'' "$ http_user_agent" "$ http_x_forwarded_for "'; access_log/data1/logs/bbs.xoyo.com _ access. log bbs;} # reverse proxy of Forum attachments. the download speed is limited to 256 kB/second. server {listen 80; server_name att03.bbs.xoyo.com att02.bbs.xoyo.com att01.bbs.xoyo.com; location/{# restrict download speed to 256 k/slimit_rate 256 k; proxy_pass http://xx.xx.xx.19 ; Proxy_set_header Host $ host; proxy_set_header X-Forward-For $ remote_addr;} access_log off;} # locate the SNS community in Xiaoyao Jianghu, manage the background to a server, and view images, flash, javascript and CSS web cache server {listen 80; server_name hu.xoyo.com * .hu.xoyo.com; location/{proxy_pass http://php_server_pool ; Proxy_set_header Host $ host; proxy_set_header X-Forward-For $ remote_addr;} location ~. *\. (Gif | jpg | jpeg | png | bmp | swf | js | css) $ {proxy_cache cache_one; proxy_cache_valid 20010 m; proxy_cache_valid 3041 m; proxy_cache_valid 301302 ih; then any 1 m; proxy_cache_key $ host $ uri $ is_args $ args; proxy_set_header Host $ host; proxy_set_header X-Forward-For $ remote_addr; proxy_pass http://php_server_pool ;} Location ~ ^/Admincp. php {proxy_set_header Host $ host; proxy_set_header X-Forward-For $ remote_addr; proxy_pass http://xx.xx.xx.4 ;} Access_log/data1/logs/hu.xoyo.com _ accsee. log ;}}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces the application of Nginx load balancing in Kingsoft Xiaoyao network N years ago, including some content. For more information, see PHP Chinese network (www.php1.cn )!