In Jinshan Carefree Network, the front-end load balancer Server is Nginx, two Nginx server for a group, assume a variety of types of load balancing services, two load balancer servers are active, each binding a public network virtual IP, as a load balancer server, when one of the failures, The other one takes over the virtual IP of the failed server. Configure the nginx.conf code as follows
Code:
User www www;work_processes8; Error_log/data1/logs/nginx_error.log Crit;pid/usr/local/webserver/nginx/nginx.pid;#specifies The value for maximum file descriptors the can is opened by this process Worker_rlimit_nofile 51200events{use Epoll; Worker_connections51200;} http{include mine.types; Default_typeApplication/octet-strem;#charset Utf-8Server_names_Hash_bucket_size -K Client_header_buffer_size +K Large_client_header_buffers4 +K Sendfile on;#tcp_nopush on;Keepalive_timeout -; Tcp_nodelay on; Fastcgi_connect_timeout -; Fastcgi_send_timeout -; Fastcgi_Read_timeout -; Fastcgi_buffer_size -K Fastcgi_buffers4 -K Fastcgi_busy_buffers_size -K Fastcgi_temp_file_write_size -K gzip on; Gzip_min_length1K Gzip_buffers4 -K Gzip_http_version1.1Gzip_comp_level2; Gzip_types text/plain application/x-javascript text/css application/xml; Gzip_vary on; Limit_zone Anti_attack$binary _remote_addr TenM#允许客户端请求的最大单文件字节数Client_max_body_size -M#缓冲区代理缓冲用户端的最大字节数 can be understood as existing to local and then passed to the userClient_body_size -K#跟后端服务器连接的超时时间_发起握手等候响应超时时间Proxy_connect_time -;#连接成功后_等待后端服务器响应时间_其实已经进入后端的派对等候处理Proxy_Read_timeout -;#后端回传时间_规定时间内传完所有数据Proxy_send_timeout -;#代理请求缓存区, save the user's header information for nginx to rule processingProxy_buffer_size -K Proxy_buffers4 +K Proxy_busy_buffers_size -K Proxy_temp_file_write_size -K#缓存Proxy_temp_path/data2/proxy_temp_path; Proxy_cache_path/data2/proxy_cache_path levels=1:2Keys_zone=cache_one: $M inactive=1D max_size=5; Upstream myserver_pool{server xx.xx.xx.1: theweight=1max_fails=2fail_timeout= -S Server xx.xx.xx.2: theweight=1max_fails=2fail_timeout= -S Server xx.xx.xx.3: theweight=1max_fails=2fail_timeout= -S } upstream php_server_pool{server xx.xx.xx.4: theweight=1max_fails=2fail_timeout= -S Server xx.xx.xx.5: theweight=1max_fails=2fail_timeout= -S Server xx.xx.xx.6: theweight=1max_fails=2fail_timeout= -S Server xx.xx.xx.7: theweight=1max_fails=2fail_timeout= -S Server xx.xx.xx.8: theweight=1max_fails=2fail_timeout= -S } Upstream bbs_server_pool{ip=Hash; Server xx.xx.xx.9: themax_fails=2fail_timeout= -S Server xx.xx.xx.Ten: themax_fails=2fail_timeout= -S Server xx.xx.xx. One: themax_fails=2fail_timeout= -S Server xx.xx.xx. A: themax_fails=2fail_timeout= -S } upstream cms_server_pool{server xx.xx.xx. -: theweight=1max_fails=2fail_timeout= -S Server xx.xx.xx. -: theweight=1max_fails=2fail_timeout= -S } upstream pic_server_pool{server xx.xx.xx. the: theweight=1max_fails=2fail_timeout= -S Server xx.xx.xx. -: theweight=1max_fails=2fail_timeout= -S } upstream xoyohimsg_server_pool{server xx.xx.xx. -:3245; Server xx.xx.xx. -:3245Down }#xoyo. com domain name to www.xoyo.comserver {Listen the; server_name xiyo.com; Rewrite ^/(. *) http:xoyo.com/permanent; Acces_log/data1/logs/xoyo.com_access.log; }#用户中心HTTP/ssl Encrypted browsingserver {Listen443; 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; }#图片服务器, different paths access different servers on the backendserver {Listen the; 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; }#音频电台文件下载 for a simple anti-theft chain #limit_zone Media%binary_remote_addr 10m;server {Listen the; server_name media.xoyo.com; Location/{Proxy_pass http://cms_server_pool; Proxy_Set_header Host$host; Proxy_Set_header x-forward-for$remote _addr; Valid_reference Nine blocked www.xoyo.com *.xoyo.com www.kingsoft.com *.kingsoft.com www.kingsoft.cn *.kingsoft.cn;if($invalid _referers) {rewrite ^/http://www.xoyo.com; }} Access_log/data1/logs/media.xoyo.com_access.log; }# "Fun to talk" Webim product load Balancing, reverse proxy two HTTP serversserver {Listen the; server_name hi.xoyo.com;#反向代理一款定制开发的高性能消息队列HTTP服务器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;Web Caching #论坛负载均衡并对图片, Flash, JavaScript, CSS, static HTMLserver {Listen the; server_name bbs.xoyo.com *.bbs.xoyo.com bbs.xoyo.kingsoft.com; Location/{Proxy_pass 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 $ TenM Proxy_cache_valid304 1M Proxy_cache_valid301 302Ih Proxy_cache_valid any1M 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" $body _bytes_sent "$http _referer" ' "$http _user_agent" "$http _x_forwarded_for" '; Access_log/data1/logs/bbs.xoyo.com_access.log BBS;}#论坛附件反向代理, limit download speed to 256k/secondsserver{Listen the; server_name att03.bbs.xoyo.com att02.bbs.xoyo.com att01.bbs.xoyo.com; Location/{#限制下载速度为256k/SLimit_rate theK Proxy_pass http://xx.xx.xx. +; Proxy_Set_header Host$host; Proxy_Set_header x-forward-for$remote _addr; } Access_log off;}#逍遥江湖SNS社区, manage to navigate to a server on the background, and FLASH,JAVASCRIPT,CSS Web caching for pictures,server {Listen the; 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 $ TenM Proxy_cache_valid304 1M Proxy_cache_valid301 302Ih Proxy_cache_valid any1M 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 NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Application of Nginx load balance in Jinshan Xiaoyao net in n years ago