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

测试成功

相关推荐
goehou1 小时前
改错一行 fstab,SSH 就再也连不上了
linux·运维·故障恢复·fstab
Csvn2 小时前
Nginx 可观测性与工程化:指标、告警与发布回滚演练
后端·nginx
贝锐3 小时前
远程运维如何实现网页触达:制造企业引入向日葵SDK重构机床运维实战
运维·sdk·web
无奈笑天下4 小时前
银河麒麟高级服务器操作系统【通过 sysctl 调整内核网络参数】操作方法
运维·服务器·网络
MSTcheng.6 小时前
【LinuxIO篇】Linux学习第二十三弹——Linux重定向到底改了什么?printf为何会写进文件,一文搞懂fd与dup2
linux·运维·服务器·操作系统·重定向·文件描述符
fengkai454520 小时前
Python运维
运维·python·监控·psutil·ipy
无足鸟ICT1 天前
【RHCA+】_proc_pid_task_
linux·运维·服务器
weixin_404679311 天前
cc 在 linux 安装
linux·运维·服务器
云上工程笔记1 天前
大模型平台私有化部署怎么选?2026年合规要求、运维难度与架构成本评测
运维·架构