I cannot login to minio console behind nginx proxy. Both are started as docker container with docker compose. I can login to minio without proxy by accessing localhost:9001, but I cannot when behind proxy. I got response 401 invalid login, though I am using the same login as without proxy. Nginx configuration is mostly taken from minio docs. Can any one see the reason or know what can I check to login?
Part of docker compose:
nginx:
image: nginx:alpine
restart: unless-stopped
ports:
- ${FORWARD_NGINX_HTTP_PORT:-80}:80
- ${FORWARD_NGINX_HTTPS_PORT:-443}:443
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/ssl:/etc/nginx/ssl
networks:
- default
minio:
image: minio/minio
command: minio server /data/minio --console-address ":9001"
restart: unless-stopped
healthcheck:
test: [ "CMD", "mc", "ready", "local" ]
interval: 30s
timeout: 5s
retries: 3
expose:
- 9000
- 9001
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minio}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-password}
MINIO_SERVER_URL: https://s3.localhost
MINIO_BROWSER_REDIRECT_URL: https://s3.localhost/minio/ui
ports:
- ${FORWARD_MINIO_API_PORT:-9000}:9000
- ${FORWARD_MINIO_CONSOLE_PORT:-9001}:9001
volumes:
- minio-data:/data
networks:
- default
Part of nginx configuration:
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name s3.localhost;
ssl_certificate /etc/nginx/ssl/localhost.crt;
ssl_certificate_key /etc/nginx/ssl/localhost.key;
ignore_invalid_headers off;
client_max_body_size 0;
proxy_buffering off;
proxy_request_buffering off;
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://minio:9000;
}
location /minio/ui {
rewrite ^/minio/ui/(.*) /$1 break;
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";
proxy_set_header Origin '';
chunked_transfer_encoding off;
proxy_pass http://minio:9001;
}
}
Certs generated with mkcert.
2
Answers
Here’s a working configuration. The Minio console is served at https://127.0.0.1/.
🗎
docker-compose.yml
🗎
nginx/nginx.conf
The Reason of the Problem
The problem is related to the SSL certificate (seems to be self-signed) which you used for nginx to server HTTPS traffic.
Minio Console will connect to Minio Server’s storage for accessing its management data (e.g., user data at login time). Setting
MINIO_SERVER_URL
tohttps://s3.localhost
will let the console access the server (nginx proxy) via HTTPS. Due to the server’s certificate not being trusted by the console, access data from the server will fail from TLS verification, and thus result in401 invalid login
from the console.The Solutions
Solution 1: Using Internal Address to Access Minio Server
As the console and server are collocated in the same container, the console will automatically pick the container’s non-loopback address to access the storage, if the
MINIO_SERVER_URL
is not explicitly set.Solution 2: Let the Console Trust Your Own Certificate
Because, I do not know if there are any CLI options or environment variables for
minio
to trust extra certificates, we need to extend the image by adding your certificate file to the trusted certificate store of the image.adding the
localhost.crt
or theroot-ca.crt
(if you signlocalhost.crt
with your own CA) to your local system hosting docker.If not rebuild the image, directly bind mount the
/etc/ssl/certs/ca-certificates.crt
of the local system to the containerin your compose file.
alternative to (2), extend the official image: