A (master), B, C server, a primary server
Principle:
Domain name resolves to a server, a server is assigned to B, C server
Core configuration (The configuration method master does not provide services):
Upstream nginx.cn {
#ip_hash;
#server 192.168.1.228:80 weight=5;
#server 192.168.1.224:80 weight=5;
Server 192.168.1.228:80;
Server 192.168.1.240:80;
}
server{
Listen 80;
server_name nginx.cn;
Location/{
Proxy_pass http://nginx.cn;
if ($request _uri ~* ". *\. ( JS|CSS|GIF|JPG|JPEG|PNG|BMP|SWF) ($ ") {
Proxy_pass http://nginx.cn;
}
}
location/status{
Auth_basic "Nginxstatus";
Stub_status on;
Access_log on;
}
}
If the IP of the primary server is put into the upstream, the server will assign itself to load tasks, unlimited self-mobilization, will cause a dead loop.
because:Port 80 has been used to monitor the processing of load balancing, then the server can no longer use the 80 port to process access requests, you have to use a new. So we add the nginx.conf of the main server to the following code:
server{
Listen 8080;
server_name a.com;
Index index.html;
root/data0/htdocs/www;
}
All configurations (The configuration method master server does not provide services):
User www www;
Worker_processes 10;
PID Nginx.pid;
events{
Use Epoll;
Worker_connections 51200;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Keepalive_timeout 120;
Tcp_nodelay on;
Upstream nginx.cn {
#ip_hash;
#server 192.168.1.228:80 weight=5;
#server 192.168.1.224:80 weight=5;
Server 192.168.1.228:80;
Server 192.168.1.240:80;
}
server{
Listen 80;
server_name nginx.cn;
Location/{
Proxy_pass http://nginx.cn;
if ($request _uri ~* ". *\. ( JS|CSS|GIF|JPG|JPEG|PNG|BMP|SWF) ($ ") {
Proxy_pass http://nginx.cn;
}
}
location/status{
Auth_basic "Nginxstatus";
Stub_status on;
Access_log on;
}
}
}
Other webserver only need to configure the appropriate domain name to
Nginx Load Balancer Reverse Proxy