Five ways of allocating nginx upstream

Source: Internet
Author: User
Tags hash

Nginx's upstream currently supports 5 different ways of allocating

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:

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, so that each visitor has a fixed access to a back-end server that resolves the session's problem.

For example:

upstream bakend {
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.

upstream backend {
server server1;
server server2;
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

upstream backend {
server squid1:3128;
server squid2:3128;
hash $request_uri;
hash_method crc32;
}

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.