Preparation:
Proxy-Server: 1.1.1.22 (Server load balancer)
Nginx-Server23: 1.1.1.23 (web23)
Nginx-Server24: 1.1.1.24 (web24)
Environment version:
Linux Nginx-Proxy 2.6.32-358. el6.x86 _ 64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
①: Nginx is installed and configured.
WEB server pre-configuration:
[Root @ Nginx-Server23 ~] # Echo "1.1.1.23-server23">/usr/local/nginx/html/index.html
[Root @ Nging-Server24 ~] # Echo "1.1.1.24-server24">/usr/local/nginx/html/index.html
Server load balancer configuration:
[Root @ Nginx-Proxy conf] # egrep-v "# | ^ $"/usr/local/nginx/conf/nginx. conf
Worker_processes 1;
Events {
Worker_connections 1024;
}
Http {
Include mime. types;
Default_type application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
Upstream www.111cn.net {
Server 1.1.1.23: 80 weight = 20; # The weight value determines the Allocation Value. The server load balancer accesses 1.1.1.23 twice and 1.1.1.24 once.
Server 1.1.1.24: 80 weight = 10;
}
Server {
Listen 80;
Server_name www.111cn.net;
Location /{
Proxy_pass http://www.111cn.net;
}
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
}
}
}
Note: server 1.1.1.23: 80 weight = 20; equivalent to server 1.1.1.23: 80 weight = 20 max_fails = 1 fail_timeout = 10 s;
Test:
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.23-server23
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.23-server23
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.24-server24
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.23-server23
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.23-server23
[Root @ Nginx-Proxy conf] # curl 1.1.1.22
1.1.1.24-server24
Note: When one of the webservers goes down, it takes about 10 seconds for the server to be removed.