Nginx的负载均衡

1、安装ubuntu环境和redhat环境

【Tools】Ubuntu22.04安装详细教程_ubuntu22.04安装教程-CSDN博客(侵权必删)

2、构建Nginx环境

Nginx快速入门-KuangStudy-文章

3、ngnix常用命令:

cd /usr/local/nginx/sbin/
./nginx  启动
./nginx -s stop  停止
./nginx -s quit  安全退出
./nginx -s reload  重新加载配置文件
ps aux|grep nginx  查看nginx进程

4、检查ngnix环境配置

在192.168.118.131服务器下:

在192.168.118.128下:

5、实现nginx负载均衡所添加的代码:

    upstream nginx_boot{
   # 30s内检查心跳发送两次包,未回复就代表该机器宕机,请求分发权重比为1:2
   	server 192.168.118.128 weight=100 max_fails=2 fail_timeout=30s; 
   	server 192.168.118.131 weight=200 max_fails=2 fail_timeout=30s;
   # 这里的IP请配置成你WEB服务所在的机器IP
	    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;    
	        index  index.html index.htm index.jsp index.ftl;
       	    proxy_set_header Host $host;
       	    proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # 请求交给名为nginx_boot的upstream上
            proxy_pass http://nginx_boot;
        }

6、测试:

第一次轮播:界面是nihao!

第二次轮播:界面是nnn

相关推荐
大小科圣15 分钟前
lnmp平台
运维·服务器·nginx
沐千熏22 分钟前
Liunx(CentOS-6-x86_64)使用Nginx部署Vue项目
vue.js·nginx·centos
晴天Y283 小时前
nginx中upstream模块的使用。
运维·服务器·nginx
快乐非自愿5 小时前
什么是nginx的强缓存和协商缓存
nginx·spring·缓存
daizikui11 小时前
LVS+Nginx接入层架构图
服务器·nginx·lvs
deming_su18 小时前
第八课:性能优化与高并发处理方案
nginx·性能优化·node.js
Java_young18 小时前
(十七) Nginx解析:架构设计、负载均衡实战与常见面试问题
nginx·面试·负载均衡
SaebaRyo21 小时前
手把手教你在网站中启用https和http2
后端·nginx·https
若云止水1 天前
Ubuntu 下 nginx-1.24.0 源码分析 - cycle->modules[i]->ctx
linux·nginx·ubuntu