Nginx实现负载均衡,以轮询为例
轮询策略
一、单服务器实现nginx负载均衡
1.首先准备一台服务器
nginx:localhost:10000
server1:localhost:10001
server2:localhost:10002
2.配置nginx.conf
1)设置轮询策略
2)配置server1和server2
3.重启nginx服务:systemctl restart nginx
访问localhost:10000(如果是服务器,记得打开出入站端口)
二、多台服务器实现负载均衡(博主自己只有两台,以下域名为虚假的)
1.准备多服务器
nginx:localhost:10000
server1:test.ali.cn:10000(此处由于博主另一服务器已有项目,所以开了一个10000端口,也可用服务器ip)
server2:localhost:10002
2.配置nginx.conf
1)设置轮询策略
2)配置server1和server2
注意:其他服务器配置完也要重启nginx