nginx代理minio集群的websocket问题,求解决!!!

1.问题描述

nginx代理minio集群,web控制台浏览buckets下的列表一直在loading...,

不使用nginx代理地址,通过minio集群直接访问是没有问题的

从报错来看是websocket连接失败问题,按照官方文档以及其他博主的方式都配置了,仍未解决!!!!!

 

 

 

2.minio镜像版本:

minio/minio:RELEASE.2024-11-07T00-52-20Z

3.nginx版本

1.20.2

4.nginx配置

[root@minio-1 conf]# cat conf.d/minio.conf 
# 定义 Web 服务器组(Web 端口,通常为 29000)
upstream minio_web_servers {
    server 172.16.8.78:9000 max_fails=3 fail_timeout=30s;
    server 172.16.8.79:9000 max_fails=3 fail_timeout=30s;
    server 172.16.8.80:9000 max_fails=3 fail_timeout=30s;
}

# 定义 API 服务器组(API 端口,通常为 29001)
upstream minio_api_servers {
    server 172.16.8.78:9001 max_fails=3 fail_timeout=30s;
    server 172.16.8.79:9001 max_fails=3 fail_timeout=30s;
    server 172.16.8.80:9001 max_fails=3 fail_timeout=30s;
}

server {
    listen 9900;  # Web 端口监听
    server_name 172.16.8.78;

    # Web 端代理到 MinIO 集群
    location / {
        proxy_pass http://minio_web_servers;
        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 10s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }

    # 配置 WebSocket 请求路径
    location /ws/ {  # 确保路径匹配 WebSocket 请求
        proxy_pass http://minio_web_servers;  # 将请求转发到后端 MinIO 集群
        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;

        # WebSocket 特定头部设置
        proxy_http_version 1.1;  # 使用 HTTP/1.1 来支持 WebSocket
        proxy_set_header Upgrade $http_upgrade;  # WebSocket 升级请求头
        proxy_set_header Connection "upgrade";  # 连接升级头部

        # 设置超时
        proxy_connect_timeout 10s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }
}

server {
    listen 9901;  # API 端口监听
    server_name 172.16.8.78;

    # API 端代理到 MinIO 集群
    location / {
        proxy_pass http://minio_api_servers;
        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;
        
        # WebSocket 特定头部设置
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        # 设置请求超时
        proxy_connect_timeout 10s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }
}

 

posted @ 2024-11-13 14:44  Leonardo-li  阅读(182)  评论(0编辑  收藏  举报