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.测试

测试成功

相关推荐
java_logo2 小时前
HashiCorp Vault 镜像拉取与 Docker 部署全指南
运维·docker·容器
Maple_land3 小时前
Linux复习:冯·诺依曼体系下的计算机本质:存储分级与IO效率的底层逻辑
linux·运维·服务器·c++·centos
linmengmeng_13146 小时前
【Jenkins】Jenkins配置从节点 - Launch Agent
运维·servlet·jenkins
人工智能训练6 小时前
如何在 Ubuntu 22.04 中安装 Docker 引擎和 Linux 版 Docker Desktop 桌面软件
linux·运维·服务器·数据库·ubuntu·docker·ai编程
凤凰战士芭比Q6 小时前
web中间件——Nginx
前端·nginx·中间件
Maple_land7 小时前
Linux复习:系统调用与fork
linux·运维·服务器·c++·centos
996终结者7 小时前
Docker核心用途实战:彻底解决环境一致性问题
运维·docker·容器
小晶晶京京7 小时前
day61-devops
运维·devops
阿桂有点桂7 小时前
Docker搭建Ngnix、php5.6、php8、postgresql、redis
运维·服务器·docker·容器
snakecy7 小时前
Docker打包步骤
运维·docker·容器