2e232 发表于 2014-4-21 16:06:56

lnmp-nginx负载均衡

反向代理,实现负载均衡
##############################
nginx服务器:192.168.0.179
测试主机:192.168.0.179
192.168.0.34
#############################
设置负载均衡调度器:
# 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;
}
}
检测有无语法错误:
# 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:
# ./startup.shnginx -s reload
编辑测试主机34的测试页面:
# echo server34.example.com >/var/www/html/index.html(注意刷火墙)
#echoserver34.example.com>/usr/local/lnmp/nginx/html/index.html
测试:
http://www.westos.org(通过刷新以下两个页面轮询出现)
spacer.gifspacer.gif
当当掉server34的http时,再次刷新,一直出现server79.example.com ,而没有出现报错信息,这是因为nginx对后端具有健康检查,
# /etc/init.d/httpd stop
Stopping httpd:                                          
测试:
http://www.westos.org

页: [1]
查看完整版本: lnmp-nginx负载均衡