三台机器
dir 192.168.22.132
rs1 192.168.22.134
rs2 192.168.22.136
三台机器都安装nginx,源码编译yum都可以,为了方便,我这里用yum安装
vim etc/nginx/conf.d/lb.conf
upstream asheng {
server 192.168.22.134:80 weight=2;
server 192.168.22.136:80 weight=1;
}
server {
listen 80;
server_name www.123.com;
location / {
proxy_pass http://asheng/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
rs1主页改为1111111111
rs2主页改为222222222
启动三台机器nginx
/etc/init.d/nginx start
curl -x192.168.22.132:80 www.123.com
测试结果为两次1一次2
假设现在停掉rs1,结果全是2,说明nginx把宕掉的机器剔除了
原文地址:http://blog.51cto.com/chenshengsheng/2108592