Nginx configuration round-robin shunting-Load Balancing [tested]

Source: Internet
Author: User

Nginx configuration round-robin shunting-achieve Load Balancing [pass test] preparations, 3 servers, or open a virtual machine! I implement it on a virtual machine. The ip addresses are 192.168.1.10 192.168.1.11 192.168.1.12 (Environment: ngixn is installed without any configuration). The three server environments are the best. I cloned them directly from the vm. The environment is definitely the same! Not the same. I guess I have encountered many strange problems and have never tried them. 192.168.1.10 is used as the Server Load balancer server (Server Load balancer will be configured here later, and the other two servers do not need to be configured) first, let's take a look at some common load knowledge. The nginx upstream currently supports four allocation methods. 1) Round Robin (default). Each request is distributed to different backend servers one by one in chronological order, if the backend server is down, it can be removed automatically. 2) weight specifies the polling probability. weight is directly proportional to the access ratio, which is used when the backend server performance is uneven. 2) ip_hash: each request is allocated according to the hash result of the access ip address, so that each visitor accesses a backend server at a fixed time, which can solve the session problem. 3) fair (a third party) allocates requests based on the response time of the backend server. Requests with short response time are prioritized. 4), url_hash (third-party) can be configured. Open nginx at 192.168.1.10. conf only needs to add the following code in the configuration file [html] upstream www.129.com {server 192.168.1.11: 80; server 192.168.1.12: 80;} server {listen 80; server_name www.juzheke.com; location/{proxy_pass http://www.juzheke.com; required Host $ host; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header X-Forwarded-For $ response;} access_log logs/access_log; error_log logs/error_log;} practice result: http://www.juzheke.com I pointed to 192.168.1.10 by modifying the host to make the test results obvious, I modified the html vi/usr/local/nginx/html/index.html ON THE ngixn Development page and added index.html to display that the ip addresses 192.168.1.11 and 192.168.1.12 OF THE ngixn Development page must be modified, enter the http://www.juzheke.com every time you refresh, will jump to different servers on the page (of course, I am in order to be obvious, so use the round robin method, you can modify according to your needs)

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.