搭建nginx的负载均衡

1、编写一个configMap的配置文件

复制代码
events {
    worker_connections 1024;  # 定义每个worker进程的最大连接数
}

http {
    # 定义通用代理参数(替代proxy_params文件)
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    
    proxy_connect_timeout 5s;
    proxy_read_timeout 10s;
    proxy_send_timeout 10s;
    
    proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
    proxy_next_upstream_tries 3;

    upstream backend {
        #ip_hash;  # 基于客户端IP的会话保持
        server 172.16.45.33:8081 max_fails=3 fail_timeout=30s;
        server 172.16.45.33:8084 max_fails=3 fail_timeout=30s;
    }

    server {
        listen 8045;
        
        location / {
            proxy_pass http://backend;
            
            # 如果不需要单独的proxy_params文件,可以在这里直接包含参数
            # 或者保留include指令但确保文件存在
        }
        
        # 添加健康检查端点
        location = /health {
            access_log off;
            return 200 "OK";
            add_header Content-Type text/plain;
        }
    }
}

如下,key为nginx.conf

2、把该configMap的配置文件映射到容器的/ect/nginx/目录下

3、点击保存,后会启动nginx的服务。

4、访问http://ip:8045会路由到不同的后端服务。

相关推荐
众壹新能源科技3 小时前
逆变器自带无功不够用,加装5MVar SVG后功率因数从0.85回到0.99
运维·人工智能·自动化
..Dauntless..3 小时前
【Linux】一切皆文件和缓冲区
linux·运维·服务器
QMCY_jason3 小时前
x86 ubuntu2204 无gui 安装 openeuler 2203 aarch64版本
linux·运维·服务器
重生之小比特3 小时前
【Linux系统】12 进程程序替换 自定义Shell 命令行解释器
linux·运维·服务器
考拉讲支付4 小时前
母婴亲子服务平台分账架构设计:多场景多方分账与合规清结算实践
大数据·运维·人工智能·微信小程序·架构·微信公众平台
LateFrames4 小时前
“场控软件” 如何容错与运维
运维·容错·led大屏·播控系统·场控软件
あ-4 小时前
CubeSandBox配置CubeMaster CPU 超分
linux·运维·服务器
艾伦_耶格宇4 小时前
【DOCKER容器实战】-5 Docker容器镜像的构建
运维·docker·容器
速捷工控 PLC触摸屏还原程序5 小时前
S7-200 SMART程序上传提示密码?维修、改造和换机怎么选处理路径?
运维·服务器
程序员-Benothing5 小时前
Linux抓包分析教程:tcpdump、Wireshark、tshark实战
linux·运维·服务器