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

测试成功

相关推荐
大白同学4211 小时前
【Linux】进程间通信
linux·运维·服务器
..Move...2 小时前
Docker镜像制作
运维·docker·容器
my一阁2 小时前
2025-web集群-问题总结
前端·arm开发·数据库·nginx·负载均衡·web
念念不忘 必有回响4 小时前
nginx前端部署与Vite环境变量配置指南
前端·nginx·vite
码龄3年 审核中7 小时前
说说SSH的端口转发
大数据·运维·ssh
盛世隐者7 小时前
【Linux】定制Linux系统
linux·运维·服务器
..Move...9 小时前
Docker应用部署tomcat和nginx
nginx·docker·tomcat
Lxt.星翊10 小时前
MySQL(安装和卸载、数据库存储原理图)
linux·运维·windows
苹果醋310 小时前
JAVA面试汇总(二)多线程(五)
运维·vue.js·spring boot·nginx·课程设计
JustNow_Man11 小时前
Cline中模型识别任务与clinerules相关性的实现逻辑
linux·运维·ubuntu