How to assign Nginx upstream (turn)

Source: Internet
Author: User
Transferred from: http://onlyzq.blog.51cto.com/1228/557848

1. Polling (default)

Each request is assigned to a different back-end server in chronological order, and can be automatically rejected if the backend server is down.

2, Weight
Specifies the polling probability, proportional to the weight and access ratios, for situations where the performance of the backend server is uneven.
For example:

Upstream Bakend {
Server 192.168.159.10 weight=10;
Server 192.168.159.11 weight=10;
}


3, Ip_hash
Each request is allocated according to the hash result of the access IP, so that each visitor has fixed access to a back-end server that resolves the session issue.
For example:

Upstream resinserver{
Ip_hash;
Server 192.168.159.10:8080;
Server 192.168.159.11:8080;
}


4. Fair (third party)
The response time of the back-end server is allocated to the request, and the response time is short of priority allocation.

Upstream resinserver{
server Server1;
Server Server2;
Fair
}


5. Url_hash (Third Party)

Assign requests by the hash result of the access URL so that each URL is directed to the same back-end server, which is more efficient when the backend server is cached.

Example: Add a hash statement in upstream, the server statement can not write weight and other parameters, Hash_method is the use of the hash algorithm


Upstream resinserver{
Server squid1:3128;
Server squid2:3128;
Hash $request _uri;
Hash_method CRC32;
}

Tips

Upstream resinserver{#定义负载均衡设备的Ip及设备状态
Ip_hash;
Server 127.0.0.1:8000 down;
Server 127.0.0.1:8080 weight=2;
Server 127.0.0.1:6801;
Server 127.0.0.1:6802 backup;
}

In servers that need to use load balancing, add

Proxy_pass http://resinserver/;


the status of each device is set to:
1.down Indicates that the server is temporarily not participating in the load
2.weight defaults to 1.weight, the larger the load weight.
3.max_fails: The number of times that a request failed is allowed defaults to 1. When the maximum number of times is exceeded, returns the Proxy_next_upstream module-defined error
after the 4.fail_timeout:max_fails failed, the time of the pause.
5.backup: When all other non-backup machines are down or busy, request the backup machine. So the pressure on this machine is the lightest.

client_body_in_file_only Set to on can be said that the client post data logging to the file used to do debug
Client_body_temp_path settings record file directory can be set up to 3 levels of directory
location to match the URL. Can be redirected Or a new proxy load balancer


Above describes the Nginx upstream allocation method (go), including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.