Django+MinIO部署后外网预览文件出现404错误求助
解决外网访问MinIO文件时的404错误
问题根源
从Nginx错误日志能明确看出:外网请求MinIO存储的文件时,Nginx没有将请求转发到MinIO服务,反而尝试在本地/usr/share/nginx/html目录下查找文件,自然找不到对应资源,导致404。内网能正常访问是因为内网请求直接抵达MinIO服务,绕过了Nginx的错误路由逻辑。
解决方案
1. 修改Nginx配置,添加MinIO反向代理规则
打开你的Nginx站点配置文件(通常在/etc/nginx/sites-available/或/etc/nginx/conf.d/目录下),在对应server块中添加以下配置,将MinIO相关请求转发到MinIO服务:
# 匹配媒体文件bucket的请求,转发到MinIO location ~ ^/bridge-media-files-bucket/ { proxy_pass https://localhost:9000; # 保留请求Host头,确保MinIO正确识别bucket proxy_set_header Host $host; # 传递客户端真实IP proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 传递HTTPS协议信息 proxy_set_header X-Forwarded-Proto $scheme; } # 若有多个bucket,可使用更通用的规则匹配所有MinIO路径 # location ~ ^/[a-z0-9-]+/ { # proxy_pass https://localhost:9000; # 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; # }
2. 验证并重新加载Nginx配置
- 先检查配置合法性:
sudo nginx -t
- 配置无错误的话,重新加载Nginx:
sudo systemctl reload nginx
3. 额外检查项
- 确认MinIO服务正常运行:
sudo systemctl status minio - 验证外网可正常访问MinIO的9000端口(可执行
curl https://subdomain.domain.org:9000测试)
内容的提问来源于stack exchange,提问作者Timothy Tuti
相关产品推荐
相关产品推荐

