CopyCodeThe Code is as follows: HTTP
{
Upstream www.test2.com {
Server 10.1.165.36: 80 Weight = 3;
Server 10.249.198.235;
Server 10.1.168.1 down;
Server 10.1.168.2 backup;
# Ip_hash;
}
Server
{
Location /{
Proxy_pass http://www.test2.com;
Proxy_set_header host $ host;
Proxy_set_header X-real-IP $ remote_addr;
Proxy_set_header X-forwarded-for $ proxy_add_x_forwarded_for;
}
}
For nginx Server Load balancer, you need to add upstream and proxy_pass to the server.
Server 10.1.165.36: 80 Weight = 3; indicates that the server will be accessed three times the same probability.
Server 10.1.168.1 down; not used currently
Server 10.1.168.2 backup; started only when the pressure is high
Ip_hash; use IP addresses for hash matching. However, there may be some drawbacks, such as nginx cannot obtain IP addresses if it is not on the outermost layer.
Proxy_pass http://www.test2.com represents the accessed URL