首页 > 解决方案 > s3 presinged url nginx反向代理错误 - SignatureDoesNotMatch

问题描述

我想使用 pdfjs 在浏览器中显示来自 s3 的 pdf - https://mozilla.github.io/pdf.js/ 代替使用 s3 URL,我有这样的反向代理

网址 www.my-site-url.com/public/s3-presinged-url-bucket-part-with-sign-info

NGINX 块

location /public {
    proxy_pass https://XXXX.s3.us-west-2.amazonaws.com/;
}

但是 S3 抛出错误

<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>

如何正确反向代理它?

标签: amazon-s3nginx-reverse-proxypre-signed-url

解决方案


在代理到预签名的 S3 url 时,我遇到了类似的情况。一切都在开发机器上运行,但在生产中失败了,因为 CloudFront 添加了更改签名的额外标头。在我的例子中,因为我已经有了有效的预签名 URL,只要标头未被干扰,我添加proxy_pass_request_headers off;了使代理请求大致相当于直接 GET 请求。


推荐阅读