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

测试成功

相关推荐
likfishdn13 分钟前
Linux的文件与目录管理
linux·运维·服务器
chian-ocean33 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=35 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
若云止水44 分钟前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
北京耐用通信1 小时前
航空装配自动化神器Ethercat转profient网关搭配机器人精准控制
运维·机器人·自动化
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
崔lc4 小时前
linux中安装部署Jenkins,成功构建springboot项目详细教程
运维·jenkins
浪九天4 小时前
Nginx系列05(负载均衡、动静分离)
nginx·运维开发·持续部署
luojiaao4 小时前
【Jenkins】个人向-Jenkinsfile如何写
运维·jenkins