问题描述
我刚刚在 Amazon S3 上部署了一个静态网站,目前可以在这里查看:
S3 抱怨文件不存在.现在,这有什么奇怪的 - 我在我的域上使用 CloudFront.因此,当您单击该文章链接时,它会将请求发送到 CloudFront,然后 CloudFront 会尝试从 S3 存储桶中取回文件.
但是,如果您直接从 S3 访问相同的 URL,例如:http://www.rdegges.com.s3-website-us-east-1.amazonaws.com/2015/building-a-heroku-addon-planning/ 页面会加载得很好.
这里的翻译似乎有些遗漏了.
有人对我可以做些什么来修复我的设置提出建议吗?
我会冒昧地说指定的键技术上不存在,所以错误消息是技术上的准确但不能说明全部情况.这应该很容易解决.
S3 存储桶有两个¹端点、REST"和网站".他们有两个不同的功能集.网站端点提供了索引文档的神奇解析(例如 index.html,在您提供的示例中,它似乎是实际应该返回到浏览器的内容),而 REST 端点则没有.
当您在用于网站托管的存储桶前配置 CloudFront 时,您通常不想通过从下拉列表中选择存储桶名称来将源配置为S3"源;相反,您希望将其配置为自定义"源,并使用 S3 控制台中提供的网站端点主机名(例如 example-bucket.s3-website-us-east-1...
code>),否则,CloudFront 假定您希望它使用存储桶的 REST 端点(允许身份验证和私有内容,而网站端点则不允许).
由于最初回答了这个问题,因此文档被重构,所以上面显示的消息现在出现在一页之后,并且已经重新措辞,但要点是相同的.桶的名字"好像是指下拉列表中显示的选项,不是你想要的.
注意
请务必指定静态网站托管端点,而不是存储桶的名称.
http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-cloudfront-walkthrough.html
提示您将 REST 端点用于存储桶是因为如果您使用网站端点,则错误消息不会以 XML 格式显示 -- 网站端点以 HTML 而非 XML 格式返回错误消息.
如上所述为 CloudFront 分配创建新源,然后更改行为以将请求发送到新源,然后为 /*
发送 CloudFront 缓存失效请求,您应该已设置.
另见:
http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html#WebsiteRestEndpointDiff
¹两个端点.从技术上讲,有两个以上,因为所有存储桶都有至少两个可能的 REST 端点主机名……但是有两种类型的端点.存储桶还有一个可选的传输加速端点,它使用 AWS 边缘网络(为 CloudFront 提供支持的相同基础设施)进行更快/优化的传输,特别是从距离存储桶配置的区域更远的地理位置,但不使用 CloudFront 缓存.如果您激活此端点,则它看起来像 https://example-bucket.s3-accelerate.amazonaws.com
,并且对大多数请求收取额外的使用费,因为您正在使用更多的 AWS 网络并且更少的公共互联网......但是,这是端点的幕后部署的差异,而不是端点的行为.传输加速端点仍然是一个 REST 端点,所以就像其他 REST 端点一样,它没有网站托管功能.CloudFront 不允许您为源域名使用加速终端节点,因为这没有任何意义——如果允许这样的配置,请求和响应将在 AWS 边缘网络中循环两次并增加延迟和成本,而不会提供任何好处.
I've just deployed a static website to Amazon S3, which can currently be viewed here: http://www.rdegges.com.s3-website-us-east-1.amazonaws.com/
If you click any of the article links, you'll notice the following error:
S3 is complaining the file doesn't exist. Now, here's what's weird about this -- I'm using CloudFront on my domain. So when you click that article link, it's sending the request to CloudFront which then tries to fetch the file back from the S3 bucket.
However, if you visit that same URL from S3 directly, eg: http://www.rdegges.com.s3-website-us-east-1.amazonaws.com/2015/building-a-heroku-addon-planning/ the page will load just fine.
It appears that something is getting lost in translation here.
Anyone got a suggestion of what I can do to fix my settings?
I'll go out on a limb and say that the specified key doesn't technically exist, so the error message is technically accurate but doesn't tell the whole story. This should be an easy fix.
S3 buckets have two¹ endpoints, "REST" and "website." They have two different feature sets. The web site endpoint provides magical resolution of index documents (e.g. index.html, which appears to be what is actually supposed to be returned to the browser in the example you provided) while the REST endpoints don't.
When you configure CloudFront in front of a bucket used for web site hosting, you usually don't want to configure the origin as an "S3" origin by selecting the bucket name from the drop-down list; instead, you want to configure it as a "Custom" origin, and use the web site endpoint hostname as provided in the S3 console (e.g. example-bucket.s3-website-us-east-1...
) because otherwise, CloudFront assumes you want it to use the REST endpoint for the bucket (which allows authentication and private content, which the web site endpoint doesn't).
The documentation was refactored since this question was originally answered, so the message shown above now appears one page later, and has been reworded, but the gist is the same. The "name of the bucket" seems to refer to the choices shown in the drop-down, which is not what you want.
The hint that you're using the REST endpoint for the bucket is because the error message wouldn't be in XML if you were using the web site endpoint -- the web site endpoint returns error messages in HTML, instead of XML.
Create a new origin for the CloudFront distribution, as described, then change the behavior to send requests to the new origin, then send a CloudFront cache invalidation request for /*
and you should be set.
See also:
http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html#WebsiteRestEndpointDiff
¹ two endpoints. Technically, there are more than two, since all buckets have at least two possible REST endpoint hostnames... but there are two types of endpoints. Buckets also have an optional transfer acceleration endpoint that uses the AWS edge network (the same infrastructure that powers CloudFront) for faster/optimized transfers, particularly from geographic locations more distant from the region where the bucket is provisioned, but without using the CloudFront cache. This endpoint looks like https://example-bucket.s3-accelerate.amazonaws.com
if you activate it, and carries an additional usage charge for most requests since you are using more of the AWS network and less of the public Internet... but, that is a difference in the behind-the-scenes deployment of the endpoint, not the behavior of the endpoint. The transfer acceleration endpoint is still a REST endpoint, so just like the other REST endpoints, it does not have the web site hosting features. CloudFront won't let you use an acceleration endpoint for an origin domain name, because that wouldn't make sense -- if such a configuration were allowed, requests and responses would loop through the AWS Edge Network twice and increase both latency and costs without providing any benefit.
这篇关于CloudFront + S3 网站:“指定的密钥不存在";何时应显示隐式索引文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!