nginx负载均衡
针对域名作负载均衡(还可以针对目录跳转到相应的机器)
vi /etc/nginx/conf.d/lb.conf
upstream hy { server 192.168.11.160:80; server 192.168.11.20:80; } server { listen 80; server_name www.123.com; location / { proxy_pass http://hy/; proxy_set_header Host $host; } }
测试一:
curl -xlocalhost:80 www.123.com
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@dir conf.d]# curl -xlocalhost:80 www.123.com rs1rs1 [root@dir conf.d]# curl -xlocalhost:80 www.123.com rs2rs2 [root@dir conf.d]# curl -xlocalhost:80 www.123.com rs1rs1 [root@dir conf.d]# curl -xlocalhost:80 www.123.com rs2rs2 [root@dir conf.d]# curl -xlocalhost:80 www.123.com rs1rs1 [root@dir conf.d]# curl -xlocalhost:80 www.123.com rs2rs2
测试二:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
upstream hy { server 192.168.11.160:80 weight=2; server 192.168.11.20:80 weight=1; } server { listen 80; server_name www.123.com; location / { proxy_pass http://hy/; proxy_set_header Host $host; } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@dir conf.d]# curl -xlocalhost:80 www.123.com rs2rs2 [root@dir conf.d]# curl -xlocalhost:80 www.123.com rs1rs1 [root@dir conf.d]# curl -xlocalhost:80 www.123.com rs1rs1 [root@dir conf.d]# curl -xlocalhost:80 www.123.com rs2rs2 [root@dir conf.d]# curl -xlocalhost:80 www.123.com rs1rs1 [root@dir conf.d]# curl -xlocalhost:80 www.123.com rs1rs1
谢谢