我使用S3来托pipe一些静态内容,并使用一些URL重写,使一切工作。
这是我现在的configuration:
server { listen 80; ## listen for ipv4 listen [::]:80 default ipv6only=on; ## listen for ipv6 server_name "~^(.+)\.bar\.com$"; access_log /var/log/nginx/foobar-star.access.log; set $subdomain $1; rewrite ^(.*)$ /$subdomain$request_uri?; location / { proxy_pass http://foo.bar.com.s3.amazonaws.com; } }
我的问题是,如果请求是baz.bar.com我想我的url是foo.bar.com.s3.amazonaws.com/baz/index.html,如果是baz.bar.com/css/whatever .css我想要一般情况下foo.bar.com.s3.amazonaws.com/baz/css/whatever.css,我已经在configuration中覆盖。 我不能使用$ request_filename,因为S3总是提供一些东西,甚至告诉你,你所请求的键不存在,所以我需要一个通用的规则来附加到我的url index.html,以防它不存在。 我相信这是正常的索引指令不工作的原因…
为了简短:如果我试图达到baz.bar.com/index.html所有的东西都像魅力,如果我尝试baz.bar.com/它(正确)返回一个文件,告诉我,关键'baz'不存在。 我想baz.bar.com/直接呈现我的index.html,并保持一切不变。
希望我已经清楚 – 我知道这有点混乱:)
TIA
要自动将index.html添加到以代理/之前结束的每个请求,我想你想要的东西是这样的:
server { listen 80; ## listen for ipv4 listen [::]:80 default ipv6only=on; ## listen for ipv6 server_name "~^(.+)\.bar\.com$"; access_log /var/log/nginx/foobar-star.access.log; set $subdomain $1; location / { # if the request ends with /, add index.html # the break will stop nginx from looping rewrite /$ "/$subdomain${uri}index.html" break; # else, just prefix $subdomain rewrite ^ /$subdomain$request_uri? break; proxy_pass http://foo.bar.com.s3.amazonaws.com; } }
什么HTTP错误代码S3返回时,无法find密钥? 您可以使用错误代码来提供自定义错误页面,这将是索引页面。
S3错误代码列表http://docs.amazonwebservices.com/AmazonS3/latest/API/
链接configuration自定义错误页面http://articles.slicehost.com/2008/5/16/ubuntu-hardy-nginx-virtual-host-settings