准备三台nginx 服务器 一台作为负载均衡服务器 另外两台作为WEB服务器作为WEB服务器
nginx 负载均衡服务器内网IP地址 192.168.100.113 外网IP 192.168.1.123
WEB服务器1IP地址 192.168.100.114
WEB服务器2IP地址 192.168.100.115
三台nginx服务器都通过yum安装
安装nginx源
[root@localhost ~]# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
[root@localhost ~]# yum -y install nginx
nginx负载均衡服务器上的配置
vim /etc/nginx/conf.d/default.conf
upstream webservers{
server 192.168.100.115 weight=1;
server 192.168.100.114 weight=1;
}
注:该配置放在http{}内,server{}之外,否则会报错。
location / {
proxy_pass http://webservers;
proxy_set_header X-Real-IP$remote_addr;
}
注:proxy_pass http://wabservers 与upstream backend相对应,在访问192.168.1.123或相应的域名时将流量转发到webservers组
原文:http://9872158.blog.51cto.com/9862158/1898752