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>
[[email protected] 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
[[email protected] vhosts]# curl -xlocalhost:80 www.123.com
<html>
master
</html>
[[email protected] vhosts]# curl -xlocalhost:80 www.123.com
<html>
master
</html>
[[email protected] vhosts]# curl -xlocalhost:80 www.123.com
<html>
slave
</html>