Simple configuration method for load balancing of nginx
- 2020-05-09 19:39:32
- 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 will be accessed at 3 times the same rate
server 10.1.168.1 down; is not in use for the time being
server 10.1.168.2 backup; It starts when you're under a lot of pressure
ip_hash; hash matching via IP address. However, there will be some disadvantages. For example, if Nginx is not in the outermost layer, IP cannot be acquired
proxy_pass http: / / www. test2. com represent access url