AWS S3静态网站托管上的RoutingRules [英] RoutingRules on AWS S3 Static website hosting

查看:91
本文介绍了AWS S3静态网站托管上的RoutingRules的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功配置了我的S3存储桶以服务于静态网站,并且如果在存储桶中找不到文件,也将重定向到Lambda函数.

I have successfully configured my S3 bucket to serve a static website and also redirect to a lambda function if a file is not found in the bucket.

<RoutingRules>
  <RoutingRule>
    <Condition>
      <KeyPrefixEquals/>
      <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
    </Condition>
    <Redirect>
      <Protocol>https</Protocol>
      <HostName>mylambda.execute-api.us-east-1.amazonaws.com</HostName>
      <ReplaceKeyPrefixWith>/?key=</ReplaceKeyPrefixWith>
      <HttpRedirectCode>307</HttpRedirectCode>
    </Redirect>
  </RoutingRule>
</RoutingRules>

如果我使用静态网站的http网址,效果很好

it works fine if I use the http url of the static website

http://mybucket.s3-website -us-east-1.amazonaws.com/some-file.gif

,但是如果我使用https桶url则无法使用.它返回 AccessDenied

but it doesn´t work if I use the https bucket url. it returns AccessDenied

https://s3.amazonaws.com/mybucket/some-file.gif

我也尝试添加cloudfront,问题是相同的. https://mycloudfront.cloudfront.net/some-file.gif 给了我相同的 AccessDenied

I also tryied adding cloudfront and the issue is the same. https://mycloudfront.cloudfront.net/some-file.gif gives me the same AccessDenied

好像不适合使用https吗?

is like not working for https maybe?

推荐答案

第一个网址:

mybucket. s3-网站 -us-east-1.amazonaws.com/some-file.gif

mybucket.s3-website-us-east-1.amazonaws.com/some-file.gif

网站终端节点.它仅支持HTTP, HTTPS. 文档写道:

is a website endpoint. It only supports HTTP, not HTTPS. Docs write:

网站终端节点不支持HTTPS或Amazon S3访问点.

The website endpoints do not support HTTPS or Amazon S3 Access Points.

第二个网址:

s3.amazonaws.com /mybucket/some-file.gif

s3.amazonaws.com/mybucket/some-file.gif

仍在使用旧版全球端点地区.这些(即服务端点)用于 :

is Legacy Global Endpoint still used N. Virginia region. These (i.e. service endpoints) are used to:

以编程方式连接到AWS服务

connect programmatically to an AWS service

他们同时支持 HTTP和HTTPS.

They support both HTTP and HTTPS.

因此,回答您的问题 https://mybucket.s3-website-us-east-1.amazonaws.com/some-file.gif失败,因为不支持HTTPS网站端点.

Therefore, answering to your question, the https://mybucket.s3-website-us-east-1.amazonaws.com/some-file.gif fails because HTTPS is not supported for website endpoints.

https://s3.amazonaws.com/mybucket/some-file. gif 失败,因为它用于程序访问,而不是通过浏览器或curl进行.但是,如果将对象设置为 public ,则仍然应该可以访问它们.

The https://s3.amazonaws.com/mybucket/some-file.gif fails because this is used for programmatic access, not by using browser or curl. But if you set your objects as public, you should be able to access them nevertheless.

对于CloudFront,您需要提供更多信息或提出新问题.这取决于您如何设置CF Disto和存储桶.

For CloudFront you would need to provide more information, or create new question. It depends how you setup your CF disto and bucket.

这篇关于AWS S3静态网站托管上的RoutingRules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆