A detailed description of the load balancing scheme for Nginx

Source: Internet
Author: User

The Nginx load Balancing scheme is:
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:

Click ( here) to collapse or open

  1. http{
  2. Upstream SampleApp {
  3. Server <<dns entry or IP address(optional with Port)>>;
  4. Server <<another DNS entry or IP address(optional with Port)>>;
  5. }
  6. . . . .
  7. server{
  8. Listen;
  9. . . .
  10. Location/{
  11. Proxy_pass http://sampleapp;
  12. }
  13. }

Only 1 DNS entries above are inserted into the upstream section, or SampleApp, and are again mentioned in the Proxy_pass section later.
2. Minimum connection
Web requests are forwarded to the server with the fewest number of connections.
Examples of configuration are as follows:

Click ( here) to collapse or open

  1. http{
  2. Upstream SampleApp {
  3. Least_conn;
  4. Server <<dns entry or IP address(optional with Port)>>;
  5. Server <<another DNS entry or IP address(optional with Port)>>;
  6. }
  7. . . . .
  8. server{
  9. Listen;
  10. . . .
  11. Location/{
  12. Proxy_pass http://sampleapp;
  13. }
  14. }

The above example simply adds the Least_conn configuration to the upstream section. Other configurations are configured with polling.
3. IP Address 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:

Click ( here) to collapse or open

  1. http{
  2. Upstream SampleApp {
  3. Ip_hash;
  4. Server <<dns entry or IP address(optional with Port)>>;
  5. Server <<another DNS entry or IP address(optional with Port)>>;
  6. }
  7. . . . .
  8. server{
  9. Listen;
  10. . . .
  11. Location/{
  12. Proxy_pass http://sampleapp;
  13. }
  14. }

The above example simply adds the Ip_hash configuration to the upstream section. Other configurations are configured with polling.
4, weight-based load balancing
Weight-based load balancing is weighted load balancing, in which case we can configure Nginx to distribute requests more to high-provisioned back-end servers and distribute relatively few requests to low-provisioning servers.
Examples of configuration are as follows:

Click ( here) to collapse or open

  1. http{
  2. Upstream SampleApp {
  3. Server <<dns entry or IP address(optional with Port)>> Weight=2;
  4. Server <<another DNS entry or IP address(optional with Port)>>;
  5. }
  6. . . . .
  7. server{
  8. Listen;
  9. . . .
  10. Location/{
  11. Proxy_pass http://sampleapp;
  12. }
  13. }

The above example is configured on the server address and after the port weight=2, which means that every 3 requests are received, the first 2 requests are distributed to the primary server, the 3rd request is distributed to the second server, and the other configuration is the same as the polling configuration.
Also, it is important to note that weight-based load balancing and load balancing based on IP address hashes can be combined.

http://user.qzone.qq.com/2832726343
http://user.qzone.qq.com/2896551567
http://user.qzone.qq.com/2379863260
http://user.qzone.qq.com/3138767791
http://user.qzone.qq.com/2368982197
http://user.qzone.qq.com/2912901417
http://user.qzone.qq.com/2775664424
http://user.qzone.qq.com/2334792975
http://user.qzone.qq.com/2304365470
http://user.qzone.qq.com/3110520368
http://user.qzone.qq.com/3120410163
http://user.qzone.qq.com/3117439152
http://user.qzone.qq.com/3107006795
http://user.qzone.qq.com/2376275351

A detailed description of the load balancing scheme for Nginx

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.