Five Policies for configuring Server Load balancer using nginx in the production environment: nginx Server Load balancer

Source: Internet
Author: User
Tags nginx server

Five Policies for configuring Server Load balancer using nginx in the production environment: nginx Server Load balancer

Nginx upstream currently supports five allocation methods
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 weight=10;server 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;server;}

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 server statements. hash_method is the hash algorithm used.

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

Upstream bakend {# define the Ip address and device status of the Server Load balancer Device

ip_hash;server down;server weight=2;server;server backup;}

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 for the moment. 2. The default value of weight is 1. The larger the weight value, the larger the load weight. 3. max_fails: the default number of failed requests is 1. When the maximum number of failed requests is exceeded, the system returns the proxy_next_upstream module-defined error 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. It can be used to debugclient_body_temp_path from the client post data records to the file to set the directory of the record file. A maximum of three levels of directory location can be set to match the URL. you can perform redirection or perform new proxy 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: 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.