Nginx's upstream currently supports 5 different ways of allocating
1. Polling (default)
Each request is assigned to a different back-end server in chronological order, and can be automatically removed if the backend server is down.
2, Weight
Specifies the polling probability, proportional to the weight and the access ratio, for the performance of the backend server.
For example:
upstream bakend {
server 192.168.0.14 weight=10;
server 192.168.0.15 weight=10;
}
3, Ip_hash
Each request is allocated according to the hash result of the access IP, so that each visitor has a fixed access to a back-end server that resolves the session's problem.
For example:
upstream bakend {
ip_hash;
server 192.168.0.14:88;
server 192.168.0.15:80;
}
4, Fair (third party)
The response time of the backend server is allocated to the request, and the response time is short for priority assignment.
upstream backend {
server server1;
server server2;
fair;
}
5, Url_hash (third party)
The request is allocated by the hash result of the access URL, which directs each URL to the same back-end server, which is more efficient when cached.
Example: Add hash statement in upstream, server statement can not write weight and other parameters, Hash_method is the hash algorithm used
upstream backend {
server squid1:3128;
server squid2:3128;
hash $request_uri;
hash_method crc32;
}