Nginx | reverse proxy server load balancer | principle and configuration | preliminary study-PHP source code

Source: Internet
Author: User
Tags nginx reverse proxy nginx load balancing
Nginx | reverse proxy server load balancer | principle and configuration | preliminary study Nginx | reverse proxy server load balancer | principle and configuration | preliminary study

Nginx Reverse proxy
Nginx load balancing
Upstream
Http proxy

 192.168.1.10 // B server ==> 192.168.1.36/C server ==> 192.168.1.25 // the simple principle of this server load balancer is to distribute the pressure on one server to multiple servers that provide the same service., here we generally refer to the web service // for example, when we access the website www.web.com, we need to reverse proxy it to server B and server C // so here we can regard www.web.com as a route, only responsible for distribution, not handling the actual code logic // improper understanding, please also advise http {upstream web. server {server 192.168.1.36: 80 weight = 2; server 192.168.1.25: 80 weight = 1; // server 192.168.1.36: 80 weight = 1 max_fails = 3 fail_timeout = 15 s; // server 192.168.1.25: 80 backup; // server 192.168.1.123: 80 down; // # Note} server {listen 80; server_name www.web.com; location/{proxy_pass should be used in the nginx configuration file http://web.server ; Proxy_set_header Host $ host; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for; }}// the configuration is successful, For example, access http://www.web.com/info.php// Edit info on server B. the php content is echo 'This is from balance server @ B '; // edit info on the C server. the php content is echo 'This is from balance server @ C'; // The php content is accessed according to the weight of the server set in upstream, the higher weight, the higher the access frequency. // I put the C server on windows during the test, you need to disable the windows Firewall to access the/* upstream supported status parameter * // * down, indicating that the current server is not involved in server load balancer. 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 number of failed requests allowed. the default value is 1. If the maximum number of times is exceeded, an error defined by the proxy_next_upstream module is returned. Fail_timeout: the time when the service is suspended after a max_fails failure. Max_fails can be used with fail_timeout. * // * The server load balancer algorithm supported by upstream * // * Round Robin (default ). Each request is distributed to different backend servers one by one in chronological order. if a backend server goes down, the faulty system is automatically removed, so that user access is not affected. Weight specifies the round-robin Weight. the larger the Weight value, the higher the access probability assigned to it. it is mainly used when the performance of each backend server is uneven. Ip_hash. Each request is allocated based on the hash result of the access IP address. in this way, the visitor from the same IP address accesses a backend server at a fixed speed, effectively solving the session sharing problem in the dynamic web page. Fair. This is a more intelligent load balancing algorithm than the above two. This algorithm intelligently performs load balancing based on the page size and loading time, that is, requests are allocated based on the response time of the backend server, and requests are prioritized for short response time. Nginx does not support fair. to use this scheduling algorithm, you must download the Nginx upstream_fair module. Url_hash. This method distributes requests based on the hash results of the access url so that each url is directed to the same backend server, which further improves the efficiency of the backend cache server. Nginx does not support url_hash. to use this scheduling algorithm, you must install the Nginx hash package. */Nginx HttpProxy here: http://wiki.nginx.org/HttpProxyModule References in this article are from: http://freeloda.blog.51cto.com/2033581/1288553

The above is Nginx | reverse proxy server load balancer | principle and configuration | preliminary study. For more information, see PHP Chinese website (www.php1.cn )!

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.