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

测试成功

相关推荐
feng14562 分钟前
OpenSREClaw - 从 AIOps 到 RDaaS
运维
行者-全栈开发6 分钟前
【运维安全】CVE-2026-46333:Linux内核ptrace权限提升漏洞深度解析与修复指南
运维·linux内核·权限提升·ptrace·cve-2026-46333·ssh-keysign-pwn·安全修复
晚风吹红霞8 分钟前
Linux下的趣味编程 —— 进度条、Git版本控制与GDB调试实战
linux·运维·git
nan madol9 分钟前
Rocky Linux 9.5 部署 Percona XtraDB Cluster (PXC) 集群
linux·运维·服务器
linux修理工13 分钟前
使用 virt-install 命令行快速创建 KVM 虚拟机(以 CentOS 7 为例)
linux·运维·centos
|_⊙14 分钟前
进程间通信(System V 标准下的多种通信方式)
linux·运维·服务器
云登指纹浏览器19 分钟前
指纹浏览器自动化API对接实战总结:技术方案选型 + 避坑指南
运维·后端·自动化
蹉跎岁月新30 分钟前
Jenkins创建一个maven-project
运维·jenkins·maven
原来是猿41 分钟前
性能测试(1)
运维·服务器·python·压力测试
为思念酝酿的痛9 小时前
POSIX信号量
linux·运维·服务器·后端