Nginx Server Load Balancer Configuration

Source: Internet
Author: User
Tags dns entry nginx server
Common load balancing schemes include the following:
1. Polling
Polling, round Robin, distributes the client's Web requests to different back-end servers in turn, based on the order in the Nginx configuration file.
Examples of configuration are as follows:
http{
Upstream SampleApp {
Server < >;
Server <>;
}
....
server{
Listen 80;
...
Location/{
Proxy_pass Http://sampleapp;
}
}
2. Minimum connection
Web requests are forwarded to the server with the fewest number of connections.
Examples of configuration are as follows:
http{
Upstream SampleApp {
Least_conn;
Server < >;
Server <>;
}
....
server{
Listen 80;
...
Location/{
Proxy_pass Http://sampleapp;
}
}
3. IP Hash
In both of the preceding load balancing scenarios, a continuous Web request from the same client may be distributed to a different backend server for processing, so the session is more complex if it involves session sessions. It is common for database-based session persistence. To overcome the above challenges, you can use a load balancing scheme based on IP address hashing. In this case, successive Web requests from the same client will be distributed to the same server for processing.
Examples of configuration are 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 requests more to high-provisioned back-end servers and distribute relatively few requests to the low-provisioning server. The
Configuration example is as follows:
http{
Upstream SampleApp {
Server < > weight=2;
Server <>;
}
....
server{
Listen 80;
...
Location/{
Proxy_pass Http://sampleapp;
}
}
The above example weight=2 the server address and port after the configuration, which means that every 3 requests received, the first 2 requests will be distributed to the first server, the 3rd request will be distributed to the second server, the other configuration with the polling configuration.

Copyright Notice: This article for Bo Master original article, without Bo Master permission not reproduced.

Above describes the Nginx server load balancing configuration, including 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.