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

相关推荐
難釋懷11 小时前
Nginx-UrlRewrite
运维·nginx
不像程序员的程序媛13 小时前
nginx日志配置
运维·nginx
難釋懷19 小时前
Nginx高可用配置
linux·nginx·php
风曦Kisaki21 小时前
Nginx代理与LVS(NAT/DR)全方位对比
运维·nginx·lvs
難釋懷2 天前
Nginx防盗链配置
运维·nginx
Nian.Baikal2 天前
从零搭建离线地图服务:Nginx + Cesium/Leaflet 实战指南
运维·前端·nginx
身如柳絮随风扬2 天前
Docker 部署 Nginx:从入门到生产级配置实战
nginx·docker·容器
夏天测2 天前
【高危漏洞通告】NGINX ngx_http_rewrite_module 堆缓冲区溢出漏洞;详解与修复方案
运维·nginx·http
FallenQu2 天前
【漏洞】CVE-2026-42945:NGINX ngx_http_rewrite_module 堆缓冲区溢出深度分析
运维·nginx·http
UrSpecial2 天前
从零实现Nginx风格内存池
nginx·内存池