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

测试成功

相关推荐
庚昀◟14 小时前
Wsl系统下使用Ubuntu下载官网Nginx并加入系统服务
linux·nginx·ubuntu
weixin_4624462315 小时前
【原创实践】安装与配置 lua-cjson 在宝塔 Nginx 上
nginx·junit·lua
我科绝伦(Huanhuan Zhou)15 小时前
MySQL运维必备:24个核心监控参数(含查询语句+异常处理)
运维·数据库·mysql
python百炼成钢15 小时前
44.Linux RTC
linux·运维·实时音视频
武子康15 小时前
Java-179 FastDFS 高并发优化思路:max_connections、线程、目录与同步
java·开发语言·nginx·性能优化·系统架构·fastdfs·fdfs
有谁看见我的剑了?15 小时前
Rocky9.6 Samba搭建学习
linux·运维
未来之窗软件服务15 小时前
服务器运维(十六)vlang语言linuxSSH日志分析——东方仙盟炼气期
运维·服务器·服务器运维·东方仙盟
吕了了15 小时前
113 隐藏此电脑中的常用文件夹
运维·windows·系统
w***375116 小时前
在 Ubuntu 22.04 上安装和配置 Nginx 的完整指南
linux·nginx·ubuntu
p***924816 小时前
Nginx location 和 proxy_pass 配置详解
服务器·网络·nginx