The allocation algorithm currently supported by Nginx's upstream:
1. Round-robin polling 1:1 to process requests in turn (default)
Each request is processed one by one in chronological order Assigned to different application servers, if the application server goes down, it will be automatically removed, and the remaining ones will continue to be polled.
2. Weight weight (weighted polling)
By configuring the weight, the polling probability is specified. The weight is proportional to the access ratio and is used for uneven performance of the application server.
3. ip_hash hash algorithm
Each request is allocated according to the hash result of the accessed IP, so that each visitor has a fixed access to an application server, which can solve the problem of session sharing. If the application server fails, it needs to be shut down manually.
Parameter meaning:
down: Indicates that the previous server will not participate in the load temporarily
weight: The default is 1. The greater the weight, the greater the weight of the load.
max_fails: The number of allowed request failures defaults to 1. When the maximum number is exceeded, the error defined by the proxy_next_upstream module is returned.
fail_timeout: The pause time after max_fails failures.
backup: When all other non-backup machines are down or busy, request the backup machine.
upstream tg-t4 { server 10.0.0.110:8099; server 10.0.0.110:8098; } server { listen 8096; server_name www.tg-t4.com; location / { proxy_pass http://tg-t4; } }
upstream tg-t4 { server 10.0.0.110:8099 weight=2; server 10.0.0.110:8098 weight=5; } server { listen 8096; server_name www.tg-t4.com; location / { proxy_pass http://tg-t4; } }
upstream tg-t4 { server 10.0.0.110:8099; server 10.0.0.110:8098; ip_hash; } server { listen 8096; server_name www.tg-t4.com; location / { proxy_pass http://tg-t4; } }
upstream tg-t4 { server 10.0.0.110:8099; server 10.0.0.110:8098 backup; } server { listen 8096; server_name www.tg-t4.com; location / { proxy_pass http://tg-t4; } }
upstream tg-t4 { server 10.0.0.110:8099 weight=1 max_fails=2 fail_timeout=2; server 10.0.0.110:8098 weight=3 max_fails=2 fail_timeout=2 backup; } server { listen 8096; server_name www.tg-t4.com; location / { proxy_pass http://tg-t4; } }
The above is the detailed content of How to implement load balancing polling configuration in nginx. For more information, please follow other related articles on the PHP Chinese website!