gpt4 book ai didi

amazon-web-services - 如何为 Cloudfront 上的静态托管网站的子目录设置默认根对象?

转载 作者:行者123 更新时间:2023-12-03 05:13:46 30 4
gpt4 key购买 nike

如何为 Cloudfront 上静态托管网站的子目录设置默认根对象?具体来说,我希望每当用户请求 www.example.com/subdir 时都能提供 www.example.com/subdir/index.html 服务。请注意,这是为了交付保存在 S3 存储桶中的静态网站。此外,我想使用源访问身份将对 S3 存储桶的访问限制为仅 Cloudfront。

现在,我知道 Cloudfront 的工作方式与 S3 和亚马逊状态不同 specifically :

The behavior of CloudFront default root objects is different from the behavior of Amazon S3 index documents. When you configure an Amazon S3 bucket as a website and specify the index document, Amazon S3 returns the index document even if a user requests a subdirectory in the bucket. (A copy of the index document must appear in every subdirectory.) For more information about configuring Amazon S3 buckets as websites and about index documents, see the Hosting Websites on Amazon S3 chapter in the Amazon Simple Storage Service Developer Guide.

因此,即使 Cloudfront 允许我们指定默认根对象,但这仅适用于 www.example.com 而不适用于 www.example.com/subdir。为了解决这个困难,我们可以将源域名更改为指向S3给出的网站端点。这非常有效,并且允许统一指定根对象。不幸的是,这似乎与origin access identities不兼容。 。具体来说,上述链接指出:

Change to edit mode:

Web distributions – Click the Origins tab, click the origin that you want to edit, and click Edit. You can only create an origin access identity for origins for which Origin Type is S3 Origin.

基本上,为了设置正确的默认根对象,我们使用 S3 网站端点而不是网站存储桶本身。这与使用源访问身份不兼容。因此,我的问题可以归结为

  1. 是否可以为 Cloudfront 上静态托管网站的所有子目录指定默认根对象?

  2. 是否可以为 Cloudfront 提供的内容设置源访问身份,其中源是 S3 网站端点而不是 S3 存储桶?

最佳答案

IS一种方法可以做到这一点。不要通过在下拉列表中选择它来将其指向您的存储桶 (www.example.com.s3.amazonaws.com),而是将其指向您的存储桶的静态域(例如 www.example.com.s3-website-us -west-2.amazonaws.com):

enter image description here

感谢This AWS Forum thread

关于amazon-web-services - 如何为 Cloudfront 上的静态托管网站的子目录设置默认根对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31017105/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com