Five distribution methods for nginx upstream

  

upstream of nginx currently supports allocation of 5 ways

1, polling (default)

Each request is assigned one by one in chronological order Different backend servers can be automatically culled if the backend server is down.

2, weight

Specify the polling probability. The weight is proportional to the access ratio and is used for the performance of the backend server.

Example:

upstream bakend {server 192.168.0.14 weight=10;server 192.168.0.15 weight=10;}

3, ip_hash

Every Requests are allocated by the hash result of the access ip, so that each visitor has a fixed access to a backend server, which can solve the session problem.

Example:

upstream bakend {ip_hash;server 192.168.0.14:88;server 192.168.0.15:80;}

4, fair (third party)

Assign the request by the response time of the backend server, with a short response priority allocation.

upstream backend {server server1;server server2;fair;}

5, url_hash(third party)

Assign the request by the hash result of the access url, so that each The url is directed to the same backend server, which is more efficient when it is cached.

Example: Adding a hash statement in the upstream, the 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;}

tips:

upstream bakend{#Define the Ip and device status of the load balancing device

ip_hash;server 127.0 .0.1:9090 down;server 127.0.0.1:8080 weight=2;server 127.0.0.1:6060;server 127.0.0.1:7070 backup;}

In the server that needs to use load balancing

proxy_pass http://bakend/;

The status of each device is set to:

1.down means that the server before the single is not participating in the load temporarily

2 The .weight defaults to 1. The greater the weight, the greater the weight of the load.

3.max_fails : The number of times a request is allowed to fail defaults to 1. When the maximum number of times is exceeded, the error defined by the proxy_next_upstream module is returned

4.fail_timeout: The time after the failure of max_fails times.

5.backup: When all other non-backup machines are down or busy, request a backup machine. So this machine will be the lightest.

nginx supports setting multiple groups of load balancing at the same time, which is used for unused servers.

client_body_in_file_only Set to On. You can talk about the data record from the client post to the file for debugging.

client_body_temp_path Set the directory of the log file to up to 3 levels.

location Match URLs. Redirect or perform new proxy load balancing


Copyright © Windows knowledge All Rights Reserved