Nginx upstream sharing of 5 ways of weight distribution _nginx

Source: Internet
Author: User
1. 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.

2, 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 Backend {
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, 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 Backend {
Ip_hash;
Server 192.168.0.14:88;
Server 192.168.0.15:80;
}

4, 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.linuxany.com;
Server server2.linuxany.com;
Fair
}

5, 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;
}
#定义负载均衡设备的Ip及设备状态
Upstream backend{
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
Proxy_pass http://bakend/;

The status of each device is set to:
1.down indicates that the server before the single is temporarily not participating in the load
2.weight The default is 1.weight larger, the weight of the load will be greater.
3.max_fails: The number of allowed requests failed defaults to 1. Returns the error Proxy_next_upstream module definition when the maximum number of times is exceeded
4.fail_timeout:max_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 the simultaneous setting of multiple sets of load balancing to be used for unused servers.

Client_body_in_file_only set to on can be used to speak the client post from the data log to the file to do debug
Client_body_temp_path set up a directory of record files can be set up to 3 levels of directory

Location the URL. Can be redirected or new agent load balancing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.