首先你需要安装nginx
可以参考文章
https://www.cnblogs.com/caidingyu/p/11007707.html
我测试的是centos 7.9 系统,安装最新的nginx/1.21.0

image.png
配置之前,确定nginx安装成功,并且可以正常启动
如果不是root用户登录centos ,是其他用户登录centos
要使用sudo systemctl start nginx 启动nginx
打开nginx.conf
默认安装配置文件在/etc/nginx/nginx.conf里面

image.png
在/etc/nginx/nginx.conf里面添加代码
upstream demo {
server 192.168.1.2:80;
server 192.168.1.3:80;
}

image.png

image.png
用户root权限编辑 /etc/nginx/conf.d/default.conf 网站配置文件

image.png
如果是root用户登录 重启nginx用命令 systemctl restart nginx
其他用户使用sudo systemctl restart nginx

image.png
这里设定的是8080,网站访问的是http://localhost:8080

image.png
每次刷新http://localhost:8080 就会轮流访问到
http://192.168.1.2:80服务器
和http://192.168.1.3:80服务器
可以参考文章
https://blog.csdn.net/qq_36478297/article/details/112138716
详细一点的
https://www.cnblogs.com/qiuhom-1874/p/12458159.html
这样负载均衡基本搭建好使用了

image.png