NGINX Load Balancing

Source: Internet
Author: User
Tags nginx load balancing

NGINX Load Balancing
I. Load Balancing Methods

1. Round Robin

 

upstream test_up {    server localhost:8080;                server localhost:9090;                server localhost:9090;}server {       listen 80;       server_name test;       location /test.html {            proxy_pass http://test_up;       }}
When you enter http: // test/test.html in the address bar of the browser, nginx accesses the backend server in sequence as configured in test_up.

 

2. Weight Distribution

 

upstream test_up {    server localhost:8080 weight=1;    server localhost:9090 weight=2;}server {       listen 80;       server_name test;       location /test.html {            proxy_pass http://test_up;        }}

 

Based on the distribution of weights, NGINX dynamically allocates frontend requests to backend servers.

3. ip hash allocation

 

upstream test_up {    server localhost:8080 weight=1;    server localhost:9090 weight=2;    ip_hash;}server {    listen 80;    server_name test;    location /test.html {        proxy_pass http://test_up    }}

The ip hash method is to HASH client requests to backend Servers Based on the Client IP address.

 

Note: although the weight is configured after each server in the code above, the weight does not take effect after ip hash is adopted.

2. Control the SERVER

1. down indicates that the server before a ticket is not involved in the load
2. The default weight value is 1. The larger the weight value, the larger the load weight.
3. max_fails: the default number of failed requests is 1. If the maximum number of failed requests is exceeded, an error defined by the proxy_next_upstream module is returned.
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. You can use the client post data record in the file for debugging.
Client_body_temp_path: Set the directory of the record file to a maximum of three levels.
Location matches 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: 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.