搭建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会路由到不同的后端服务。

相关推荐
老友@5 小时前
RabbitMQ 延时队列插件安装与使用详解(基于 Delayed Message Plugin)
运维·分布式·docker·rabbitmq·延时队列
-SGlow-6 小时前
MySQL相关概念和易错知识点(3)(表内容的CURD、内置函数)
linux·运维·服务器·数据库·mysql
编程社区管理员7 小时前
Vue项目使用ssh2-sftp-client实现打包自动上传到服务器(完整教程)
运维·服务器·vue
PanYu——BJ7 小时前
CentOS Nginx 1.13.9 部署文档
linux·nginx·centos
UQWRJ7 小时前
菜鸟教程Linux ViVimYumApt笔记
linux·运维·笔记
sz66cm8 小时前
Linux基础 -- 内核快速向用户态共享内核变量方案之ctl_table
linux·运维·服务器
努力一点9489 小时前
ubuntu22.04系统入门 linux入门(二) 简单命令 多实践以及相关文件管理命令
linux·运维·服务器·人工智能·gpu算力
wb1899 小时前
企业WEB应用服务器TOMCAT
运维·前端·笔记·tomcat·云计算
利刃大大10 小时前
【在线五子棋对战】十一、整合封装服务器模块实现
运维·服务器·c++·项目·五子棋
UU_Yang10 小时前
Linux跑后台服务
linux·运维·服务器