First, 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.
Second, weight
Specifies the polling probability, proportional to the weight and the access ratio, for the performance of the backend server.
For example:
Copy Code code as follows:
Upstream Bakend {
Server 192.168.0.14 weight=10;
Server 192.168.0.15 weight=10;
}
Third, 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:
Copy Code code as follows:
Upstream Bakend {
Ip_hash;
Server 192.168.0.14:88;
Server 192.168.0.15:80;
}
Iv. Fair (third party)
The response time of the backend server is allocated to the request, and the response time is short for priority assignment.
Copy Code code as follows:
Upstream Backend {
server Server1;
Server Server2;
Fair
}
v. 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
Copy Code code as follows:
Upstream Backend {
Server squid1:3128;
Server squid2:3128;
Hash $request _uri;
Hash_method CRC32;
}
Tips
Copy Code code as follows:
Upstream bakend{#定义负载均衡设备的Ip及设备状态
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;
}
Increase in servers that need to use load balancing
Copy Code code as follows:
Proxy_pass http://bakend/;
The status of each device is set to:
1.down means that the server before the single temporarily does not participate in the load
2.weight defaults to 1.weight the larger the load weight.
3.max_fails: The default number of times to allow requests to fail is 1. Returns the Proxy_next_upstream module-defined error
4.fail_timeout:max_ when the maximum number is exceeded Fails after a failure, the time of the pause.
5.backup: All other non-backup machines request backup machines when down or busy. So this machine will be the lightest pressure.
Nginx supports multiple sets of load balancing to be used for unused servers.
Client_body_in_file_only set to on can be used to write data from a client post to a file for debug
Client_body_temp_path The directory where you set record files can be set up to 3 levels
location to match URLs. Can be redirected or a new agent load balancing