Nginx Load Balancing

Source: Internet
Author: User

Nginx Load Balancing
Upstream mysvr {

Server 192.168.10.121: 3333; server 192.168.10.122: 3333;} server {... location ~ * ^. + $ {Proxy_pass http: // mysvr; # redirect requests to the server list defined by mysvr}

 

  Upstream mysvr {
Server http: // 192.168.10.121: 3333; server http: // 192.168.10.122: 3333;} server {... location ~ * ^. + $ {Proxy_pass mysvr; # redirect requests to the server list defined by mysvr}

Then, let's look at some practical things.

1. Hot Standby: if you have two servers, the second server is enabled to provide services only when an accident occurs on one server. The order in which the server processes requests: AAAAAA suddenly crashes. bbbbbbbbbbbbbbbb .....

Upstream mysvr {server 127.0.0.1: 7878; server 192.168.10.121: 3333 backup; # Hot Standby}

2. Polling: by default, nginx sets the weights of all polling requests to 1. The server processes requests in the following order: ABABABABAB ....

upstream mysvr {       server 127.0.0.1:7878;      server 192.168.10.121:3333;           }

3. Weighted Round Robin (WRR): distributes requests to different servers based on the configured weights. If this parameter is not set, the default value is 1. The request order of the following servers is: ABBABBABBABBABB ....

 upstream mysvr {       server 127.0.0.1:7878 weight=1;      server 192.168.10.121:3333 weight=2;
}

4. ip_hash: nginx requests the same server from the same client ip address.

upstream mysvr {       server 127.0.0.1:7878;       server 192.168.10.121:3333;      ip_hash;    }

5. If you are not familiar with the above four balancing algorithms, it may be easier for you to take a look at the picture I used in the previous article.

So far, do you feel that the nginx Server Load balancer configuration is extremely simple and powerful? So it's not over yet. Let's continue.

Several status parameters for nginx Server Load balancer configuration are described.

  • Down indicates that the current server is not involved in server Load balancer.

  • Backup, reserved backup machine. The backup machine is requested only when all other non-backup Machines fail or are busy. Therefore, this machine is under the least pressure.

  • Max_fails: the number of failed requests allowed. The default value is 1. If the maximum number of times is exceeded, an error defined by the proxy_next_upstream module is returned.

  • Fail_timeout: the time when the service is suspended after a max_fails failure. Max_fails can be used with fail_timeout.

 upstream mysvr {       server 127.0.0.1:7878 weight=2 max_fails=2 fail_timeout=2;      server 192.168.10.121:3333 weight=1 max_fails=2 fail_timeout=1;        }

 

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.