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_processes 8;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{u Se epoll; Worker_connections 51200;} http{include mine.types; Default_type Application/octet-strem; #charset utf-8 server_names_hash_bucket_size 128k; Client_header_buffer_size 32k; Large_client_header_buffers 432k; Sendfile on; #tcp_nopush on; Keepalive_timeout 30; Tcp_nodelay on; Fastcgi_connect_timeout 300; Fastcgi_send_timeout 300; Fastcgi_read_timeout 300; Fastcgi_buffer_size 64k; Fastcgi_buffers 464k; Fastcgi_busy_buffers_size 128k; Fastcgi_temp_file_write_size 128k; gzip on; Gzip_min_length 1k; Gzip_buffers 416k; 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 300m; #缓冲区代理缓冲用户端的最大字节数 can be understood as existing to the local and then passed to the user client_body_size 128k; #跟后端服务器连接的超时时间_发起握手等候响应超时时间proxy_connect_time 600; #连接成功后_等待后端服务器响应时间_其实已经进入后端的派对等候处理proxy_read_timeout 600; #后端回传时间_规定时间内传完所有数据proxy_send_timeout 600; #代理请求缓存区, save the user's header information for nginx to rule processing proxy_buffer_size 16k; Proxy_buffers 432k; Proxy_busy_buffers_size 64k; Proxy_temp_file_write_size 64k; #缓存proxy_temp_path/data2/proxy_temp_path; Proxy_cache_path/data2/proxy_cache_path levels=1:2 keys_z>200m inactive=1d max_size=5; Upstream myserver_pool{server xx.xx.xx.1:80 weight=1 max_fails=2 fail_timeout=30s; Server xx.xx.xx.2:80 weight=1 max_fails=2 fail_timeout=30s; Server xx.xx.xx.3:80 weight=1 max_fails=2 fail_timeout=30s; } upstream php_server_pool{server xx.xx.xx.4:80 weight=1 max_fails=2 fail_timeout=30s; Server xx.xx.xx.5:80 weight=1 max_fails=2 fail_timeout=30s; Server xx.xx.xx.6:80 weight=1 max_fails=2 fail_timeout=30s; Server xx.xx.xx.7:80 weight=1 max_fails=2 fail_timeout=30s; Server xx.xx.xx.8:80 weight=1 max_fails=2 fail_timeout=30s; } upstream bbs_server_pool{Ip=hash; Server xx.xx.xx.9:80 max_fails=2 fail_timeout=30s; Server xx.xx.xx.10:80 max_fails=2 fail_timeout=30s; Server xx.xx.xx.11:80 max_fails=2 fail_timeout=30s; Server xx.xx.xx.12:80 max_fails=2 fail_timeout=30s; } upstream cms_server_pool{server xx.xx.xx.13:80 weight=1 max_fails=2 fail_timeout=30s; Server xx.xx.xx.14:80 weight=1 max_fails=2 fail_timeout=30s; } upstream pic_server_pool{server xx.xx.xx.15:80 weight=1 max_fails=2 fail_timeout=30s; Server xx.xx.xx.16:80 weight=1 max_fails=2 fail_timeout=30s; } upstream xoyohimsg_server_pool{server xx.xx.xx.17:3245; Server xx.xx.xx.18:3245 down; #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; } #用户中心HTTP/ssl Encrypted Browse 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; } #图片服务器, different paths access the backend server server {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; } #音频电台文件下载, make simple anti-theft chain #limit_zone media%binary_remote_addr 10m;server {Listen 80; 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; }# "Carefree Chat" Webim product load Balancing, reverse proxy two HTTP server servers {listen 80; 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; #论坛负载均衡并对图片, Flash, JavaScript, CSS, static HTML for Web cache server {Listen 80; 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 20010m; Proxy_cache_valid 3041m; Proxy_cache_valid 301302 IH; Proxy_cache_valid any 1m; 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 "$h Ttp_referer "" "$http _user_agent" "$http _x_forwarded_for"; Access_log/data1/logs/bbs.xoyo.com_access.log BBS;} #论坛附件反向代理, limit download speed to 256k/sec server{Listen 80; server_name att03.bbs.xoyo.com att02.bbs.xoyo.com att01.bbs.xoyo.com; Location/{#限制下载速度为256k/slimit_rate 256k; Proxy_pass http://xx.xx.xx.19; Proxy_set_header Host $host; Proxy_set_header x-forward-for $remote _addr; } Access_log off;} #逍遥江湖SNS社区, manage the background to a server, and flash,javascript,css for the picture, 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 20010m; Proxy_cache_valid 3041m; Proxy_cache_valid 301302 IH; Proxy_cache_valid any 1m; 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.
The above describes the N-year-old nginx load balancing in Jinshan Carefree network application, including the aspects of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!