Nginx代理传递给S3

时间:2019-04-05 19:19:10

标签: amazon-web-services nginx heroku amazon-s3 proxy

某些问题已传递给S3。

location ~ ^/abc/(.*)$ {
  set $bucket abcd.s3-website-us-east-1.amazonaws.com;
  proxy_http_version     1.1;
  proxy_set_header       Connection "";
  proxy_set_header       Authorization '';
  proxy_set_header       Host $bucket;
  proxy_hide_header      x-amz-id-2;
  proxy_hide_header      x-amz-request-id;
  proxy_hide_header      x-amz-meta-server-side-encryption;
  proxy_hide_header      x-amz-server-side-encryption;
  proxy_hide_header      Set-Cookie;
  proxy_ignore_headers   Set-Cookie;
  proxy_intercept_errors on;
  add_header             Cache-Control max-age=31536000;

  proxy_pass             http://$bucket/$1;
}

当我做https://example.com/abc时,代理可以通过。但是,由于像href这样的静态文件都指向绝对路径(即href="/123"),因此当我单击链接时,它将重定向example.com/123并返回404。我是在example.com/abc/123上执行一个get请求,它将解决。

我的问题是如何做到这一点,以便来自绝对路径的请求 (/123)会解析为example.com/abc/123吗?

我试图使用sub_filter模块来正确安装,但是我无法使其与我分叉的Heroku Buildpack一起正常工作。 Repo to buildpack

导致错误的原因:

nginx: [emerg] unknown directive "sub_filter" 

最后,我实际上没有访问S3存储桶上的静态文件的权限,该部分实际上是由另一个团队管理的。

编辑:更正,路径不是相对的

0 个答案:

没有答案