nginx 负载均衡

1.环境准备

我使用的说centos7的系统

1.20版本的nginx

另外还有3台虚拟机

主机:192.168.163.142

两台服务器:服务器A--192.168.163.140

服务器B---192.168.163.141

2.配置服务器A和B

找到nginx下的html目录,编辑其中的index.html(在此之前,可以先进行备份)

复制代码
[root@localhost nginx]# find / -name html
/var/www/html
/usr/share/doc/pam-1.1.8/html
/usr/share/doc/pcre-devel-8.32/html
/usr/share/nginx/html
[root@localhost nginx]# cd /usr/share/nginx/html
[root@localhost html]# ls
50x.html  index.html
[root@localhost html]# cp index.html index.html.bak
[root@localhost html]# ls
50x.html  index.html  index.html.bak
[root@localhost html]# vim index.html

服务器A同上。

3.配置nginx的配置文件

找到nginx的配置文件,对其进行修改

复制代码
[root@localhost ~]# find / -name nginx
/etc/logrotate.d/nginx
/etc/nginx
/var/log/nginx
/var/cache/nginx
/usr/sbin/nginx
/usr/lib64/nginx
/usr/share/nginx
/usr/libexec/initscripts/legacy-actions/nginx
[root@localhost ~]# cd /etc/nginx
[root@localhost nginx]# ls
conf.d          mime.types  nginx.conf   uwsgi_params
fastcgi_params  modules     scgi_params
[root@localhost nginx]# vim nginx.conf
[root@localhost nginx]# systemctl restart nginx

在http{}的模块下添加以下内容,进行自定义权重

4.测试

测试成功

相关推荐
Ruiery15 小时前
Linux 6.6内核并发与同步(五):mutex 可睡眠锁
linux·运维·服务器
莫晓燚15 小时前
双机部署若依 (RuoYi‑Vue) 传统环境部署---实战
linux·运维·数据库·redis·mysql·nginx·ruoyi
开开心心就好16 小时前
竖式除法出题工具,整除余数混合模式
运维·服务器·前端·javascript·ocr·perl·1024程序员节
领麦微红外16 小时前
红外测温传感器 赋能充电桩热安全与运维智能化
运维·安全·产品经理·智能硬件
余额瞒着我当琳18 小时前
Linux初识:Linux的历史,计算机的发展脉络,发行版本,选购云服务器,安装Xshell,第一次连接,基础命令指南
linux·运维·服务器
时间售卖铺18 小时前
Docker实战:一键部署轻量级容器
运维·docker·云原生
山乐1913118 小时前
麒麟系统,安装Nginx并配置https证书
运维·nginx·https
月落汀兰18 小时前
拒绝配置写死镜像!K8s 存储卷与配置管理,PV/PVC、ConfigMap、Secret 实战避坑指南
运维·kubernetes
服务器硬件项目经理19 小时前
《超节点修仙录》· 第一卷·炼气期【第04话】 超节点 vs 普通服务器——不就是多插了几张卡吗?
运维·服务器·人工智能·嵌入式硬件·深度学习·机器学习