With load balancing, modify the configuration HTTP node as follows:
#设定http服务器, using its reverse proxy function to provide load balancer support http { #设定mime类型, type defined by Mime.type file include /etc/nginx/ mime.types; default_type application/octet-stream; #设定日志格式 access_log /var/log/ nginx/access.log; #省略上文有的一些配置节点 # ..... #设定负载均衡的服务器列表 upstream mysvr { #weigth参数表示权值, the higher the weight, the greater the chance of being allocated server 192.168.8.1x:3128 weight=5; #本机上的Squid开启3128端口 , it is not necessary to squid server 192.168.8.2x:80 Weight=1; server 192.168.8.3x:80 weight=6; } upstream mysvr2 { #weigth参数表示权值, the higher the weight, the greater the probability of being allocated server 192.168.8.x:80 weight=1; server 192.168.8.x:80 weight=6; } # First Virtual Server server { # Listening on 80 ports of 192.168.8.x listen 80; server_name 192.168.8.x; #对aspx后缀的进行负载均衡请求 location ~&nbSP;. *\.aspx$ { #定义服务器的默认网站根目录位置 root /root; #定义首页索引文件的名称 index index.php index.html index.htm; #请求转向mysvr defined list of servers proxy_pass http://mysvr ; #以下是一些反向代理的配置可删除 . proxy_redirect off; #后端的Web服务器可以通过X-FOrwarded-for get the user real Ip proxy_set_header Host $host; proxy_set_header X-Real-IP $remote _addr; proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; #允许客户端请求的最大单文件字节数 client_max_body_size 10m; #缓冲区代理缓冲用户端请求的最大字节数, client_body_buffer_size 128k; # Nginx-to-backend server connection time-out (proxy connection timed out) proxy_connect _timeout 90; #连接成功后, back-end server response time (proxy receive timeout) proxy_read_timeout 90; #设置代理服务器 (nginx) buffer size for saving user header information proxy_buffer_size 4k; #proxy_buffers缓冲区, the average page below 32k, so set proxy_buffers 4 32k; #高负荷下缓冲大小 (proxy_buffers*2) proxy_busy_buffers_size 64k; #设定缓存文件夹大小, greater than this value, will be transmitted from the upstream server proxy_temp_file_write_size 64k; } }}
Nginx Load Balancer Configuration detailed