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 (192.168.1.60)
RS2 only intranet IP (192.168.1.70)
(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 192.168.1.60 weight=2; #权重可不写
Server 192.168.1.70 weight=1;
}
server {
Listen 80;
server_name www.llzd.com;
Location/{
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 192.168.31.100weight=100;". 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:
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