1.8-nginx Load-balancing cluster

Source: Internet
Author: User
Tags custom name nginx load balancing

In front of the content we have already mentioned Nginx load balancing function, in my opinion it actually and Nginx's generation

Management is the same function, but the former agent of a machine changed to proxy more than one machine. Nginx Load Balancing and LVS

In contrast, Nginx belongs to the more advanced application layer, does not involve the IP and the kernel change, it just simply put the user's request

Forward to the back of the machine. This means that the rear-end RS does not need to configure the public IP.

(1) Environmental description

Nginx Dispatcher (a public network ip192.168.31.80 and an intranet ip192.168.1.80).

RS1 only intranet IP (

RS2 only intranet IP (

(2) configuration , first install Nginx. If you used to have LVS, remember to empty the Ipvsadm rule

Editing the configuration file on the Nginx dispatcher

Source installation configuration file location vim/usr/local/nginx/conf/vhosts/lb.conf

Yum installation configuration file location Vim vim/etc/nginx/conf.d/lb.conf

Add the following:

Upstream WYP {

Ip_hash; #可不写

Server weight=2; #权重可不写

Server weight=1;


server {

Listen 80;

server_name www.llzd.com;


Proxy_pass http://wyp/;

Proxy_set_header Host $host;

Proxy_set_header X-real-ip $remote _addr; #可不写

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; #可不写



Note: You will find this configuration and the Nginx proxy configuration We said earlier, just a upstream, this upstream used to define the back end of the RS, can write only one. Ip_hash is an nginx scheduling algorithm , plus this line will reach

To the effect that a user's request will be distributed moderately to a fixed Rs. The advantage is that you can avoid the same

A situation in which a user's request is distributed to a different machine, causing the session to be lost. Inside the upstream, the IP behind the RS can also be

Weights, such as "Server;". Another thing to note is that the test behind upstream is

A custom name, can be written casually, the only requirement is to be consistent with the proxy_pass behind.


Test Curl www.wuyaoping.com on this machine

Using the Web test, first modify the C:\Windows\System32\drivers\etc\hosts file, point the domain name to the local network address or

Network addresses are available.

1.8-nginx Load-balancing cluster

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.