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

测试成功

相关推荐
Deutsch.1 小时前
负载均衡Haproxy
运维·负载均衡·haproxy
不做无法实现的梦~2 小时前
mid360连接机载电脑,远程桌面连接不上的情况
运维·服务器·电脑
运维成长记2 小时前
关于linux运维 出现高频的模块认知
运维·职场和发展·云计算
IT成长日记3 小时前
【自动化运维神器Ansible】Ansible常用模块之archive模块详解
运维·自动化·ansible·常用模块·archive
晴天¥3 小时前
阶段1--域名服务器
运维·服务器·网络
禁默3 小时前
进程调度的艺术:从概念本质到 Linux 内核实现
linux·运维·服务器
Azure DevOps4 小时前
在Azure DevOps的工作项中使用markdown
运维·microsoft·flask·azure·devops
先做个垃圾出来………4 小时前
CI/CD与DevOps集成方法
运维·ci/cd·devops
qq_447705314 小时前
宝塔通过docker部署JupyterHub指南【常见错误处理】
运维·docker·容器
卡比巴拉—林4 小时前
HAProxy 实验指南:从零开始搭建高可用负载均衡系统
运维·负载均衡