反向代理,實現負載均衡
##############################
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