Minio nginx配置https和http问题解决,疑难症全网首发

以下问题基本上是因为NGINX代理出现

一、API直接返回单独的错误: io.minio.errors.ErrorResponseException: Access denied

二、API直接返回的错误:The request signature we calculated does not match the si

三、预览文件或者图片返回错误

<Error>
<Code>AccessDenied</Code>
<Key>1672887375909191680.png</Key>
<BucketName>9269770290188565a62b37a563d10a5a</BucketName>
<Resource>/9269770290188565a62b37a563d10a5a/1672887375909191680.png</Resource>
<RequestId>176BDD0C470B0828</RequestId>
<HostId>dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8</HostId>
</Error>

以上三个问题都属于Access denied 这个情况,但是原因却各有不同,解决方案也不一样。无论是国内还是国外解决方案都很贫瘠。所以经过我两天的踩坑已经解决问题

这些问题都是只有在使用nginx代理情况下才会出现,如果正常使用ip是不会有问题的,但是直接用ip的话,难免暴露出一些问题和不专业。

问题一的原因及解决方案

出现这个的原因大多数情况下,确实与服务器时间是否一致有关,但是不是所有都是。

部分是由于调用了minioClient.bucketExists(); 这个API则引起异常问题

解决方式,只要不调用判断是否存在桶api即可,改成获取所有桶,然后遍历判断

该问题具体原因不详,我之前本地nginx代理没有问题,但是使用服务器的nginx代理却不能使用这个api,nginx版本是同样的。这个情况,后续有空我会继续研究。我提交过issue,但是被忽略了。

问题二的原因及解决方案

出现该问题主要是因为api请求验签不通过,因为验签在nginx转发时将host和port是否有携带。

扫描二维码关注公众号,回复: 16803445 查看本文章

解决方案:

client连接接口分为两种,域名和端口

例如:http://oss.baidu.com,http://oss.baidu.com:6661

nginx 配置时需要区分这两种方式:

proxy_set_header Host $http_host;  #域名形式配置,例如:http://oss.baidu.com (后缀没有斜杠)

proxy_set_header Host $host:$server_port; #例如: http://oss.baidu.com:6661

完整示例:

9000端口就是data接口(例如上传和客户端连接),9001是minio控制台端口

server {
        listen 80;
        server_name oss.baidu.com;
		
		location / {
			proxy_set_header Authorization $http_authorization;
			proxy_set_header Host $http_host;
			proxy_pass http:/127.0.0.1:9000;
			proxy_set_header  X-Real-IP    $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
		}
	}

https 配置也同理。其实只需要http用于上传,https用于文件预览或下载即可,示例

只要是同一个域名或域名与端口即可

预览地址:https://oss.baidu.com/storage/桶名/文件名.png?xxxx

storage 是定义的上下文

	server {
		listen 443 ssl http2;
        server_name oss.baidu.com;
		gzip on;
		ssl_certificate    fullchain.pem;
		ssl_certificate_key    privkey.pem;
		ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
		ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
		ssl_prefer_server_ciphers on;
		ssl_session_cache shared:SSL:10m;
		ssl_session_timeout 10m;
		add_header Strict-Transport-Security "max-age=31536000";
		
		location ^~/storage/ {
			proxy_buffering off;
		    proxy_set_header Host $http_host;
			rewrite ^/storage/(.*)$ /$1 break;
			proxy_pass http://127.0.0.1:9000;
			proxy_set_header  X-Real-IP    $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
		}
		
	}

问题三的原因以及解决办法

这个问题就解决方式非常简单

1.域名域名:端口,必须要完全统一,否则会因为host不同签名不通过

2.9000端口(minio默认端口)上传,也必须要9000端口查看或下载。9001不得使用

3.根据我上述的nginx配置就可以解决以问题二和问题三。

猜你喜欢

转载自blog.csdn.net/Qensq/article/details/131382578
今日推荐