Simple configuration method for nginx load balancing
- 2020-05-06 12:17:14
- OfStack
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;
}
}
Nginx load balancing requires adding upstream and proxy_pass
in Server
server 10.1.165.36:80 weight = 3; means that this server has 3 times the same probability of accessing
server 10.1.168.1 down; does not use
for the time being
server 10.1.168.2 backup;
is activated only when the pressure is high
ip_hash; hash matching by IP address. However, there are some disadvantages. For example, if Nginx is not in the outermost layer, IP and
cannot be obtained
proxy_pass http: / / www. test2. com