Nginx Load Balancer Cluster
Nginx load balancing function In fact and Nginx proxy is the same function, just to the previous agent a machine to agent more than one machine, nginx load and compared to LVS, Nginx belongs to a more advanced application layer, not involved in IP and kernel changes, It simply forwards the user's request to the back of the machine, so the backend real server does not need to configure the public IP
First, configure the environment
Nginx Dispatcher (a public network 192.168.101.230 and an intranet IP192.168.104.230)
Rs1 Intranet IP (192.168.104.108)
RS2 Intranet IP (192.168.101.109)
Second, the specific configuration process
[Email protected] ~]# cd/usr/local/nginx/conf/vhosts/
[[email protected] vhosts]# ls
default.conf proxy.conf test.conf
[Email protected] vhosts]# vim lb.conf
Upstream Daixuan {
Ip_hash;
Server 192.168.104.108:80;
Server 192.168.104.109:80;
}
server {
Listen 80;
server_name www.daixuanlinux.com;
Location/{
Proxy_pass http://Daixuan/;
Proxy_set_header Host $host;
}
}
[Email protected] vhosts]#/etc/init.d/nginx restart
Stop nginx: [OK]
Starting nginx: [OK]
[Email protected] vhosts]# ipvsadm-c
[Email protected] vhosts]# iptables-t nat-f
[Email protected] vhosts]# iptables-f
[Email protected] vhosts]# NETSTAT-LNP
Active Internet connections (only servers)
Proto recv-q send-q Local address Foreign address Stat e pid/program name
TCP 0 0 0.0.0.0:3306 0.0.0.0:* LIST EN 2492/mysqld
TCP 0 0 0.0.0.0:80 0.0.0.0:* LIST EN 2947/nginx
Third, testing
[Email protected] vhosts]# curl-xlocalhost:80 www.123.com
Turns out rs1rs1 and RS2R2 switch
This article is from the "Daixuan" blog, make sure to keep this source http://daixuan.blog.51cto.com/5426657/1737460
Nginx Load Balancer Cluster