Nginx can load balance according to client IP, set ip_hash in upstream, can select the same back-end server for clients in the same Class C address segment, unless that backend server is down.
Nginx upstream currently supports the allocation of 5 ways:
1. Polling (default)
each request is assigned to a different back-end server in chronological order, and can be automatically rejected if the backend server is down.
Upstream Backserver { server 192.168.0.14; Server 192.168.0.15;
2. Assigning weights
Specifies the polling probability, proportional to the weight and access ratios, for situations where the performance of the backend server is uneven.
Upstream Backserver { server 192.168.0.14 weight=10; Server 192.168.0.15 weight=10;
3. IP binding Ip_hash
Each request is allocated according to the hash result of the access IP, so that each visitor has fixed access to a back-end server that resolves the session issue.
Upstream Backserver { ip_hash; Server 192.168.0.14:88; Server 192.168.0.15:80;
4. Fair (third party)
The response time of the back-end server is allocated to the request, and the response time is short of priority allocation.
Upstream Backserver { server server1; Server Server2; Fair
5. Url_hash (third party)
Assign requests by the hash result of the access URL so that each URL is directed to the same back-end server, which is more efficient when the backend server is cached.
Upstream Backserver { server squid1:3128; Server squid2:3128; Hash $request _uri; Hash_method CRC32;
In servers that need to use load balancing, add
Proxy_pass http://backserver/; Upstream backserver{ Ip_hash; Server 127.0.0.1:9090 down; (down indicates that the server is temporarily not participating in the load) server 127.0.0.1:8080 weight=2; (weight defaults to 1.weight, the greater the weight of the load) server 127.0.0.1:6060;
Max_fails: The number of times that a request failed is allowed defaults to 1. Returns the error defined by the Proxy_next_upstream module when the maximum number of times is exceeded
Fail_timeout:max_fails times after a failure, the time of the pause
Nginx Load Balancing