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

测试成功

相关推荐
凯子坚持 c4 小时前
Docker实战深度解析:从Nginx部署到私有镜像仓库管理
nginx·docker·eureka
Shylock_Mister5 小时前
Linux C线程编程全指南
linux·运维·c语言
Autism....6 小时前
服务器理解
运维·服务器
天亮之前_ict6 小时前
【故障排查】intel 服务器安装Win server 2019蓝屏解决方法
运维·服务器
熙客7 小时前
Linux:监控命令
linux·运维
飞鱼&7 小时前
Linux 常用命令
linux·运维·服务器
喵了几个咪7 小时前
使用Bazel构建你的Kratos微服务
java·运维·微服务
偶像你挑的噻7 小时前
4-Linux驱动开发-字符设备驱动
linux·运维·驱动开发
2401_865854888 小时前
AI软件可以帮助我自动化哪些日常任务?
运维·人工智能·自动化
qq_401700418 小时前
Linux 信号机制
linux·运维·服务器