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

测试成功

相关推荐
ALex_zry4 小时前
SSH主机密钥验证失败:全面解决方案与技术手册
运维·ssh
厦门辰迈智慧科技有限公司5 小时前
城市排水管网流量监测系统解决方案
运维·服务器
我没有开挂5 小时前
旧 docker 版本通过 nvkind 搭建虚拟多节点 gpu 集群的坑
运维·docker·容器
qq_339282235 小时前
centos中libc.so.6No such file的解决方式
linux·运维·centos
小鸡,啄米6 小时前
centos9安装docker 配置docker代理
运维·docker·容器
水银嘻嘻6 小时前
12 web 自动化之基于关键字+数据驱动-反射自动化框架搭建
运维·前端·自动化
在肯德基吃麻辣烫6 小时前
Netdata在Ubuntu环境下的安装与配置:构建实时系统监控与性能分析平台
linux·运维·ubuntu
不念霉运7 小时前
Gitee DevOps:中国企业数字化转型的“本土化加速器“
运维·gitee·团队开发·代码规范·devops·代码复审
安迪小宝7 小时前
6 任务路由与负载均衡
运维·python·celery
遇见火星7 小时前
jenkins流水线常规配置教程!
运维·docker·jenkins