Nginx series (thirteen nginx load balancing)

Source: Internet
Author: User
Tags nginx server nginx load balancing
: This article mainly introduces the Nginx series (thirteen nginx server load balancer). For more information about PHP tutorials, see. I. server load balancer configuration

# Server load balancer upstream webserver {server192.168.27.134: 8080; server192.168.27.135: 80; server192.168.27.136: 80 ;}# reverse proxy server {listen80; server_name www.test01.com; location/{proxy_pass http://webserver ; Principal; proxy_set_header Host $ host; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header X-Forwarded-For $ scheme; }# web server {listen8080; server_name www.test01.com; access_log logs/host. access. log main; location/{root/web/www/thinkphp; index. php index.html index.htm; if (! -E $ request_filename) {rewrite ^/(. *) $/index. php/$1 last ;}} location ~ [^/] \. Php (/| $) {root/web/www/thinkphp; fastcgi_index index. php; fastcgi_pass127.0.0.1: 9000; include fastcgi_params; fastcgi_split_path_info ^ (. +? \. Php) (/. *) $; your SCRIPT_FILENAME $ document_root $ response; fastcgi_param SCRIPT_NAME $ response; fastcgi_param PATH_INFO $ response; fastcgi_param PATH_TRANSLATED $ document_root $ response ;}}

II. load balancing algorithm

1. Round Robin (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 (solves the session sharing problem)

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

4. fair allocates requests based on the response time of the backend server. requests with short response time are prioritized. (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 distributes requests according to the hash result of the access url so that each url is directed to the same backend server. the backend server is effective when it 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

3. related configuration

Weight: specifies the round-robin Weight. the larger the Weight value, the higher the access probability to be allocated. it is mainly used when the performance of each backend server is uneven.

Down: indicates that the current server is not involved in server load balancer for the moment. it is usually used with ip_hash.

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 maximum number of failed requests generated when the server is available within a certain period of time (set in the fail_timeout parameter). The default value is 1. You can disable the check by setting it to 0. these errors are defined in proxy_next_upstream and fastcgi_next_upstream (404 errors will not add max_fails.

Fail_timeout: The server may be unavailable after a connection request fails to be attempted due to the size specified by max_fails within this time period, similarly, it specifies the server unavailable time (before the next attempt to initiate a connection request). The default value is 10 seconds. fail_timeout is not directly related to the frontend response time, however, you can use proxy_connect_timeout and proxy_read_timeout for control.

IV. References

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

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

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

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.