Far*_* ET 7 nginx docker docker-compose minio
我正在尝试将example.com/minio位置重定向到 minio 控制台,该控制台在 nginx 代理后面运行,两者均由 docker compose 文件运行。我的问题是,当我尝试将 minio 端点反向代理到路径时,/minio它不起作用,但是当我minio在 nginx 反向代理中的根路径上运行反向代理时,它起作用。我真的无法找出问题所在。
这是我的撰写文件:
services:
nginx:
container_name: nginx
image: nginx
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ./log/nginx:/var/log/nginx/
minio:
image: minio/minio
container_name: minio
volumes:
- ./data/minio/:/data
command: server /data --address ':9000' --console-address ':9001'
environment:
MINIO_ROOT_USER: minio_admin
MINIO_ROOT_PASSWORD: minio_123456
ports:
- 9000
- 9001
restart: always
logging:
driver: "json-file"
options:
max-file: "10"
max-size: 20m
healthcheck:
test: ["CMD", "curl", "-f", "http://127.0.0.1:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
Run Code Online (Sandbox Code Playgroud)
我的nginx配置是这样的:
server {
listen 80;
server_name example.com;
# 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;
access_log /var/log/nginx/service-access.log;
error_log /var/log/nginx/service-error.log debug;
location / {
return 200 "salam";
default_type text/plain;
}
location /minio {
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;
}
}
Run Code Online (Sandbox Code Playgroud)
以及卷曲端点 ( ) 的响应$ curl -k http://example.com/minio:
server {
listen 80;
server_name example.com;
# 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;
access_log /var/log/nginx/service-access.log;
error_log /var/log/nginx/service-error.log debug;
location / {
return 200 "salam";
default_type text/plain;
}
location /minio {
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我也被这个问题困扰了很久,最后终于解决了。
据我所知,使这项工作对我有用的关键变化在于:
rewrite指令(而不是依赖于 Nginx proxy_pass+URI 行为,这似乎对我不起作用)。resolver短超时的指令(以便解决将服务重新安排到其他节点上的问题)。$upstream以防止 DNS 缓存。我必须稍微更改一下您的设置,以便现在 Minio S3 API 在后面提供服务minio.example.com,同时可以通过 访问 UI Web 控制台minio.example.com/console/。
我已经编辑了您的配置文件如下:
docker-compose.yml:
services:
nginx:
container_name: nginx
image: nginx
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ./log/nginx:/var/log/nginx/
minio:
image: minio/minio
container_name: minio
volumes:
- ./data/minio/:/data
command: server /data --address ':9000' --console-address ':9001'
environment:
MINIO_SERVER_URL: "http://minio.example.com/"
MINIO_BROWSER_REDIRECT_URL: "http://minio.example.com/console/"
MINIO_ROOT_USER: minio_admin
MINIO_ROOT_PASSWORD: minio_123456
ports:
- 9000
- 9001
restart: always
logging:
driver: "json-file"
options:
max-file: "10"
max-size: 20m
healthcheck:
test: ["CMD", "curl", "-f", "http://127.0.0.1:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
Run Code Online (Sandbox Code Playgroud)
nginx.conf:
server {
listen 80;
server_name minio.example.com;
# 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;
access_log /var/log/nginx/service-access.log;
error_log /var/log/nginx/service-error.log debug;
# 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;
# 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;
}
}
Run Code Online (Sandbox Code Playgroud)
哈!
| 归档时间: |
|
| 查看次数: |
10673 次 |
| 最近记录: |