Nginx Series (13 Nginx load balancer)

Source: Internet
Author: User
Tags nginx load balancing
I. Load-balancing configuration

# Load BalancerUpstreamwebserver {Server192.168.27.134:8080;Server192.168.27.135:80;Server192.168.27.136:80;}# Reverse ProxyServer{Listen the;server_namewww.test01.com; Location/ {Proxy_passHttp://webserver;Proxy_redirectoff;Proxy_set_headerHost$host;Proxy_set_headerX-real-ip$remote _addr;Proxy_set_headerX-forwarded-for$proxy _add_x_forwarded_for; }}# Web ServerServer{Listen8080;server_namewww.test01.com;Access_logLogs/host.access.log main; Location/ {Root/web/www/thinkphp;Indexindex.php index.html index.htm;if(!-E$request _filename) {rewrite ^/(.*)$/index.php/ $ Last; }    } Location~ [^/]\.php (/|$){Root/web/www/thinkphp;Fastcgi_indexindex.php;Fastcgi_pass127.0.0.1:9000;includeFastcgi_params;Fastcgi_split_path_info^ (. +?\.php) (/.*) $;Fastcgi_paramScript_filename$document _root$fastcgi _script_name;Fastcgi_paramScript_name$fastcgi _script_name;Fastcgi_paramPath_info$fastcgi _path_info;Fastcgi_paramPath_translated$document _root$fastcgi _path_info; }}

Two. Load Balancing algorithm

1. Polling (default)

upstream webserver {    server192.168.27.134:8080;    server192.168.27.135:80;    server192.168.27.136:80;}

2.weight

upstream webserver {    server192.168.27.134:8080 weight=1;    server192.168.27.135:80 weight=2;    server192.168.27.136:80 weight=2;}

3.ip_hash (resolving session sharing issues)

upstream webserver {    ip_hash;    server192.168.27.134:8080;    server192.168.27.135:80;    server192.168.27.136:80;}

4.fair allocates requests by the response time of the backend server, with a short response time priority allocation. (Third party)

upstream webserver {    server192.168.27.134:8080;    server192.168.27.135:80;    server192.168.27.136:80;    fair;}

Reference: Http://wiki.nginx.org/HttpUpstreamFairModule

5.url_hash assigns requests by the hash result of the access URL, directing each URL to the same back-end server, which is more efficient when the backend server is cached. (Third party)

upstream webserver {    server192.168.27.134:8080;    server192.168.27.135:80;    server192.168.27.136:80;    hash$request_uri;}

Reference: Http://wiki.nginx.org/HttpUpstreamRequestHashModule

6. Consistent hash (third party)
Reference: Http://wiki.nginx.org/HttpUpstreamConsistentHash

Three. Related configurations

Weight: Specifies the polling weights, the higher the Weight value, the higher the access probability is allocated, which is mainly used in the case of uneven performance of each server in the backend.

Down: Indicates that the current server is temporarily not participating in load balancing and is typically used with Ip_hash.

Backup: Reserved Standby machine. When all other non-backup machines fail or are busy, the backup machine is requested, so the pressure on this machine is the lightest.

Max_fails: The maximum number of failed requests that can occur at a certain time (set in the Fail_timeout parameter) to check if this server is available, the default is 1. Setting it to 0 closes the check, which is defined in Proxy_next_upstream and Fastcgi_next_upstream (404 error does not cause max_fails to increase).

Fail_timeout: This server may not be available after a failed attempt to connect to the size of max_fails at this time, and it also specifies the time that the server is unavailable (before the next attempt to initiate a connection request), which defaults to 10 seconds, Fail_ Timeout is not directly related to the front-end response time, but can be controlled using proxy_connect_timeout and proxy_read_timeout.

Four. References

http://baidutech.blog.51cto.com/4114344/1033718

http://lobert.iteye.com/blog/1929623

http://blog.csdn.net/poechant/article/details/7256184

The above describes the Nginx series (13 Nginx load Balancing), including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.