nginx 转发 minio Access Denied 问题

2,912 阅读1分钟

如题, 使用 nginx 将部分请求转发至 miniio,但是 nginx 返回 Access Denied XML 文件

官网中的 nginx 配置在这里

定位问题的大概步骤

  1. 尝试不通过 nginx ,直接访问 miniio ,此时是可以访问的,因此问题出在nginx 的配置,或者其他地方
  2. 经过搜索,发现有人提到时区问题, date 查看时间发现,时间没什么问题,因此排除时区因素
  3. 检查 bucket 的访问策略,bucket 是 public 状态,并且 access rule 中已经添加 * read write, 因此排除 桶自身的配置因素
  4. 检查 nginx 配置,经过修改测试,定位到问题如下
# 这是官网的配置
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;
           proxy_http_version 1.1;
           proxy_set_header Connection "";
           chunked_transfer_encoding off;

            proxy_pass http://10.103.237.135:9000; # miniio
            }

# 经过实践后,可行的配置
        location /online-project/ {
            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;
           proxy_http_version 1.1;
           proxy_set_header Connection "";
           chunked_transfer_encoding off;

            proxy_pass http://10.103.237.135:9000/; # miniio
        }

只有 location 以及 proxy_pass 这部分做了改变,感觉还是对 nginx 的配置不熟悉吧.

ricensoftwares.com.cn/index.php?c…

对于 proxy_pass 的斜杠问题,得结合 location 来讲。

location /docs/ {  
    proxy_pass http://127.0.0.1:8080;  
}

    这种 IP、端口后面没有 /,是不带 URI 的方式,nginx 会保留 location 中的路径。所以,访问 http://127.0.0.1/docs/,实际上访问的是 http://127.0.0.1:8080/docs/。

location /docs/ {  
    proxy_pass http://127.0.0.1:8080/;  
}

    这种 IP、端口后面有 /,是带 URI 的方式,nginx 将会使用别名的方式来对 URL 进行替换。所以,访问 http://127.0.0.1/docs/,实际上访问的是 http://127.0.0.1:8080/,/docs/ 替换成了 /。