反向代理,实现负载均衡
##############################
nginx服务器:192.168.0.179
测试主机:192.168.0.179
192.168.0.34
#############################
设置负载均衡调度器:
[root@server79 conf]# vim nginx.conf
upstream westos{
server 192.168.0.34 weight=2; //设置权重
server 192.168.0.119;
}
设置负载均衡调度器所调用的负载均衡服务器(在此以www.westos.org为例):
server {
listen 80;
server_name www.westos.org;
location / {
proxy_pass http://westos;
}
}
检测有无语法错误:
[root@server79 conf]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
重新加载nginx:
[root@server79 bin]# ./startup.sh nginx -s reload
编辑测试主机34的测试页面:
[root@server34 ~]# echo server34.example.com >/var/www/html/index.html(注意刷火墙)
[root@server79html]#echoserver34.example.com>/usr/local/lnmp/nginx/html/index.html
测试:
http://www.westos.org(通过刷新以下两个页面轮询出现)
当当掉server34的http时,再次刷新,一直出现server79.example.com ,而没有出现报错信息,这是因为nginx对后端具有健康检查,
[root@server34 html]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]
测试:
http://www.westos.org
原文:http://cuanlf.blog.51cto.com/8241982/1399169