1、安装及配置
#安装Nginx参考lnmp学习笔记
vim /usr/local/nginx/conf/vhosts/lb.conf#创建配置文件
upstream river {
server 10.10.13.247:80;
server 10.10.13.248:80;
}
server {
listen 80;
server_name www.123.com;
location / {
proxy_pass http://river/;
proxy_set_header Host $host;
}
}
2、启动nginx并测试
curl -xlocalhost:80 www.123.com
<html>
master
</html>
[root@redhat02 vhosts]# curl -xlocalhost:80 www.123.com
<html>
slave
</html>
#可以看到已经交替显示结果
3、如果给他加个权参数
此处 server 10.10.13.247:80;
server 10.10.13.248:80;
改成
server 10.10.13.247:80 weight=2;
server 10.10.13.248:80 weight=1;
测试可以看到显示结果为两次master一次slave
[root@redhat02 vhosts]# curl -xlocalhost:80 www.123.com
<html>
master
</html>
[root@redhat02 vhosts]# curl -xlocalhost:80 www.123.com
<html>
master
</html>
[root@redhat02 vhosts]# curl -xlocalhost:80 www.123.com
<html>
slave
</html>
本文出自 “愺艮搥豩” 博客,请务必保留此出处http://riverxyz.blog.51cto.com/533303/1789300
原文地址:http://riverxyz.blog.51cto.com/533303/1789300