1. Round Robin (default)
Each request is distributed to different backend servers one by one in chronological order. If the backend servers are down, they can be removed automatically.
2. Weight
Specify the round-robin probability. weight is proportional to the access ratio, which is used when the backend server performance is uneven.
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 address, so that each visitor accesses a backend server at a fixed time, which can solve the session problem.
For example:
Upstream bakend {
Ip_hash;
Server 192.168.0.14: 88;
Server 192.168.0.15: 80;
}
4. Fair (third party)
Requests are allocated based on the response time of the backend server. Requests with short response time are prioritized.
Upstream backend {
Server server1;
Server server2;
Fair;
}
5. url_hash (third-party)
Requests are allocated based on the hash result of the access URL so that each URL is directed to the same backend server. The backend server is effective when it is cached.
For example, add a hash statement to upstream. Other parameters such as weight cannot be written to the server statement. hash_method is the hash statement used.Algorithm
Upstream backend {
Server squid1: 3128;
Server squid2: 3128;
Hash $ request_uri;
Hash_method CRC32;
}
TIPS:
Upstream bakend {# define the IP address and device status of the Server Load balancer 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;
}
Add
Proxy_pass http: // bakend /;
The status of each device is set:
1. Down indicates that the server before a ticket is not involved in the load
2. The default weight value is 1. The larger the weight value, the larger the load weight.
3. max_fails: the default number of failed requests is 1. If the maximum number of failed requests is exceeded, an error defined by the proxy_next_upstream module is returned.
4. fail_timeout: The pause time after max_fails fails.
5. Backup: Requests the backup machine when all other non-Backup machines are down or busy. Therefore, this machine is under the least pressure.
Nginx supports setting multiple groups of Server Load balancer instances for unused servers.
Client_body_in_file_only is set to on. You can use the client post data record in the file for debugging.
Client_body_temp_path: Set the directory of the record file to a maximum of three levels.
Location matches the URL. You can perform redirection or perform new proxy load balancing.