Nginx server load balancer configuration

Source: Internet
Author: User
Tags dns entry
: This article mainly introduces the nginx server load balancer configuration. if you are interested in the PHP Tutorial, refer to it. Common load balancing solutions include the following:
1. Round Robin
Round Robin (Round Robin) distributes client Web requests to different backend servers in sequence based on the order in the Nginx configuration file.
The configuration example is as follows:
Http {
Upstream sampleapp {
Server < >;
Server <>;
}
....
Server {
Listen 80;
...
Location /{
Proxy_pass http: // sampleapp;
}
}
2. minimum connections
Web requests are forwarded to servers with the least number of connections.
The configuration example is as follows:
Http {
Upstream sampleapp {
Least_conn;
Server < >;
Server <>;
}
....
Server {
Listen 80;
...
Location /{
Proxy_pass http: // sampleapp;
}
}
3. IP hash
In the preceding two server load balancer solutions, consecutive Web requests from the same client may be distributed to different backend servers for processing. Therefore, if Session is involved, the Session will be complicated. Common is database-based session persistence. To overcome the above problems, you can use the IP address hash-based load balancing solution. In this way, the continuous Web requests of the same client are distributed to the same server for processing.
The configuration example is as follows:
Http {
Upstream sampleapp {
Ip_hash;
Server < >;
Server <>;
}
....
Server {
Listen 80;
...
Location /{
Proxy_pass http: // sampleapp;
}
}
4. weight-based load balancing
In this way, we can Configure Nginx to distribute more requests to high-configuration backend servers and distribute a relatively small number of requests to low-configuration servers.
The configuration example is as follows:
Http {
Upstream sampleapp {
Server < > Weight = 2;
Server <>;
}
....
Server {
Listen 80;
...
Location /{
Proxy_pass http: // sampleapp;
}
}
In the preceding example, weight = 2 is configured after the server address and port, which means that every three requests are received, the first two requests are distributed to the first server, 3rd requests are distributed to the second server. other configurations are the same as those in the round robin configuration.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the configuration of nginx server load balancer, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.

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.