This article to share the content is about Nginx and PHP installation and configuration seven of the Nginx load balancing 5 strategies, has a certain reference value, the need for friends can refer to
Nginx Can be load-balanced according to client IP , set ip_hash in upstream, you 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 different ways
1. Polling (default)
each request is assigned to a different back-end server in chronological order if the back-end server is downOff, can be automatically removed.
upstream Backserver {
server 192.168.0.14;
server 192.168.0.15;
}
2. Assigning Weights
Specify the polling chance, weightis proportional to the access ratio and is used for uneven performance of back-end servers.
upstream Backserver {
server 192.168.0.14 weight=10;
server 192.168.0.15 weight=10;
}
3. IP binding Ip_hash
each request is accessed by IPThe hash result is assigned so that each visitor has fixed access to a backend server that can solve the session problem.
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)
by Access URLHash result to allocate the request 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;
}
server that needs to use load balancingIncrease in
Proxy_pass http://backserver/;
Upstream backserver{
Ip_hash;
server 127.0.0.1:9090 down; ( Downrepresents the server before a singleTemporarily not participating in the load)
server 127.0.0.1:8080 weight=2; (Weightdefault is 1.weightThe bigger the load, the greater the weight
server 127.0.0.1:6060;
server 127.0.0.1:7070 Backup; (all other non-backupWhen the machine is down or busy, request the backup machine)
}
max_fails: The default number of times to allow requests to fail is 1.Returns the error defined by the Proxy_next_upstream module when the maximum number of times is exceeded
fail_timeout:max_fails the time of the pause after the second failure
Reference article:
Http://www.cnblogs.com/andashu/p/6377323.html
http://blog.csdn.net/xiajun07061225/article/details/9318871