为作为 docker 服务运行的 MinIO 服务器配置 Nginx 的正确方法是什么

为作为 docker 服务运行的 MinIO 服务器配置 Nginx 的正确方法是什么

我只是尝试将代理从 Nginx 传递到 Docker Minio 服务;但是,使用我当前的 nginx 配置文件,它无法按预期工作,并且当我从 Minio 控制台(Web 界面)浏览任何 Minio 存储桶时,它一直在加载。请注意,从本地网络浏览时,minio 服务器工作正常。minio docker 服务的当前 nginx 配置文件如下:

Nginx 配置文件:

server {
    listen 80;
    listen [::]:80;
    server_name s3.mysite.com;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name s3.mysite.com;

    ssl_certificate /etc/letsencrypt/live/s3.mysite.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/s3.mysite.com/privkey.pem;

    # To allow special characters in headers
    ignore_invalid_headers off;
    # Allow any size file to be uploaded.
    # Set to a value such as 1000m; to restrict file size to a specific value
    client_max_body_size 0;
    # To disable buffering
    proxy_buffering off;

    # Proxy requests to the bucket "photos" to MinIO server running on port 9000
    location /blog/ {
        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_set_header Host $http_host;

        proxy_connect_timeout 300;
        # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        chunked_transfer_encoding off;

        proxy_pass http://minio:9000;
    }

    location / {
        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_set_header Host $http_host;

        proxy_connect_timeout 300;
        # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        chunked_transfer_encoding off;

        proxy_pass http://minio:9001;
    }
}

Docker 撰写文件:

  minio:
    image: minio/minio
    ports:
        - "9000:9000"
        - "9001:9001"
    volumes:
      - ../s3-bucket:/data
    env_file:
      - config/.env.minio.prod
    command: server /data --console-address :9001

网络浏览器错误:

Firefox can’t establish a connection to the server at wss://s3.mysite.com/ws/objectManager. BrowserHandler.tsx:105:14
Error in websocket connection. Attempting reconnection... BrowserHandler.tsx:140:12
Websocket Disconnected. Attempting Reconnection... BrowserHandler.tsx:132:12
Websocket not available. BrowserHandler.tsx:126:14
Websocket not available.

我认为 Nginx 配置文件中缺少一些内容,无法访问 Docker 服务上的两个端口。我理解的端口9001用于控制台功能,端口9000用于数据处理。但不确定如何适当地将代理传递到两个端口。

答案1

几天前我也遇到过类似的需求。以下是我所做的

  1. 创建两个 A 记录在我的 DNS 提供商上minioapi.mypage.comminioweb.mypage.com用于访问 API 和 Web 控制台

  2. 使用自定义 nginx.conf 文件 Minio 团队建议 https://min.io/docs/minio/linux/integrations/setup-nginx-proxy-with-minio.html

  3. 部署Minio 和 nginx 作为 docker compose 文件

作为参考,这是我的 nginx.conf 文件,稍后会将其安装到我的 nginx 容器中

  user www-data;
  worker_processes auto;
  pid /run/nginx.pid;
  events {}
  
  http {
  
  include /etc/nginx/mime.types;
  server_tokens off;
  
  server {
  listen       443 ssl;
  listen  [::]:443 ssl;
  server_name  minioapi.mypage.com;
  ignore_invalid_headers off;
  client_max_body_size 0;
  proxy_buffering off;
  proxy_request_buffering off;
  ssl_certificate           /etc/nginx/ssl/archive/npm-4/fullchain1.pem;
  ssl_certificate_key       /etc/nginx/ssl/archive/npm-4/privkey1.pem;
  ssl_session_cache   shared:SSL:10m;
  ssl_session_timeout 1440m;
  ssl_session_tickets off;
  ssl_protocols TLSv1.2 TLSv1.3;
  ssl_prefer_server_ciphers off;
  ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA";
  
  access_log /dev/stdout;
  error_log /dev/stdout info;
  
  location / {
  proxy_set_header Host $http_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 300;
  proxy_http_version 1.1;
  proxy_set_header Connection "";
  chunked_transfer_encoding off;
  proxy_pass http://192.168.1.161:9000/;
  }
  }
  
  server {
  listen       443 ssl;
  listen  [::]:443 ssl;
  server_name minioweb.mypage.com;
  ignore_invalid_headers off;
  client_max_body_size 0;
  proxy_buffering off;
  proxy_request_buffering off;
  ssl_certificate           /etc/nginx/ssl/archive/npm-3/fullchain1.pem;
  ssl_certificate_key       /etc/nginx/ssl/archive/npm-3/privkey1.pem;
  ssl_session_cache   shared:SSL:10m;
  ssl_session_timeout 1440m;
  ssl_session_tickets off;
  ssl_protocols TLSv1.2 TLSv1.3;
  ssl_prefer_server_ciphers off;
  ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA";
  access_log /dev/stdout;
  error_log /dev/stdout info;
  location / {
  proxy_set_header Host $http_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_set_header X-NginX-Proxy true;
  real_ip_header X-Real-IP;
  proxy_connect_timeout 300;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  chunked_transfer_encoding off;
  proxy_pass http://192.168.1.161:9090/; 
  }
  }
  
  server {
  listen 80 http2 default_server;
  return 301 https://$host$request_uri;
  }
  
  
  }

这是我的docker compose:

---
version: '3.7'
services:
  minio:
    image: quay.io/minio/minio:RELEASE.2023-06-19T19-52-50Z
    container_name : minio
    ports:
      - 9000:9000
      - 9090:9090
      - 8021:8021
    environment:
      MINIO_ROOT_USER: rootuser
      MINIO_ROOT_PASSWORD: rootpassword
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3
    volumes:
      - ${HOME}/minio/data:/data
    command: server /data --console-address ":9090"

  nginx-rp:
    container_name: nginx-reverse-proxy
    image: nginx:1.25.1
    volumes:
        - ./conf:/etc/nginx:ro    
    ports:
    - "80:80"
    - "443:443"    
    restart: unless-stopped

答案2

您尚未配置 nginx 代理来实现 websockets。

你需要类似....的东西。

location /ws/ {
            proxy_pass http://minio:9001;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header Host $host;
        }

相关内容