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

问题描述 投票:0回答:1

我只是想代理从 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
负责数据处理。但不确定如何适当地代理传递到两个端口。

docker nginx docker-compose nginx-reverse-proxy minio
1个回答
0
投票

我也被这个问题困扰了很久,终于解决了。

据我所知,使这项工作对我有用的关键变化是:

  • 手动指定
    rewrite
    指令(而不是依赖于 Nginx proxy_pass+URI 行为,这似乎对我不起作用)。
  • 设置
    resolver
    指令并设置短超时(以便解决将服务重新调度到其他节点上的问题)。
  • 设置
    $upstream
    以防止 DNS 缓存。

我在下面编辑了您的配置文件:

nginx.conf:

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;

    # Use Docker DNS
    # You might not need this section but in case you need to resolve
    # docker service names inside the container then this can be useful.
    resolver 127.0.0.11 valid=10s;
    resolver_timeout 5s;

    # Apparently the following line might prevent caching of DNS lookups
    # and force nginx to resolve the name on each request via the internal
    # Docker DNS.
    set $upstream "minio";

    # Minio Console (UI)
    location /console/ {

        # This was really the key for me. Even though the Nginx docs say 
        # that with a URI part in the `proxy_pass` directive, the `/console/`
        # URI should automatically be rewritten, this wasn't working for me.
        rewrite ^/console/(.*)$ /$1 break;

        proxy_pass http://$upstream:9001;

        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 requests to the bucket "photos" to MinIO server running on port 9000
    location /blog/ {

        # Redirect /blog/* requests to /photos/*
        rewrite ^/blog/(.*)$ /photos/$1 break;

        proxy_pass http://$upstream:9000;

        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;

        # To support websocket
        # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        chunked_transfer_encoding off;
    }

    # Proxy requests to the Minio API on port 9000
    location / {

        proxy_pass http://$upstream:9000;

        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;

        # To support websocket
        # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        chunked_transfer_encoding off;

    }


}

docker-compose.yml

minio:
    image: minio/minio
    ports:
        - "9000:9000"
        - "9001:9001"
    volumes:
        - ../s3-bucket:/data
    #env_file:
    #  - config/.env.minio.prod
    environment:
        MINIO_SERVER_URL: "https://s3.mysite.com/"
        MINIO_BROWSER_REDIRECT_URL: "https://s3.mysite.com/console/"    
        MINIO_ROOT_USER: minio
        MINIO_ROOT_PASSWORD: minio123
    command: server /data --console-address :9001 /data

哈!

© www.soinside.com 2019 - 2024. All rights reserved.