有一个叫 www.foo.site
的桶.在那个网站上有一个登陆页面,一个关于页面和一些页面 bar/*
文件夹。每个bar/*
有一个 index.html 页面:bar/a/index.html、bar/b/index.html 等。
登陆页面运行良好(意味着 www.foo.site 将在我浏览时加载)但 /about/index.html
页面和/bar/index.html
当我点击我的关于链接等时,页面没有得到服务。如果我 curl
我得到 404 的 URL。我试过分别设置源路径和源域名:
第一次尝试:
domain name: www.foo.site.s3.amazonaws.com
origin path: (blank)
第二次尝试:
domain name: s3-us-west-1.amazonaws.com
origin path: www.foo.site
两者的默认文档都是 index.html。
没有一个工作。 上面提到的所有 S3 页面都可以直接浏览。 意义 https://s3-us-west-1.amazonaws.com/www.foo.site/bar/index.html加载预期的 html。
这一定是我缺少的一些 Cloudfront 设置。可能是我的 DNS 记录中的某些内容?是否可以通过 Cloudfront 在 S3“文件夹”中提供 html 文件?
最佳答案
这里有一些资源在通过 https://domain/folder/
从 S3 隐式提供 index.html 时很有帮助。而不是必须明确使用 https://domain/folder/index.html
:
配置 CloudFront 分配时的关键是:
do not configure a default root object for your CloudFront distribution
如果您将 index.html 配置为默认根对象,则
https://domain/
将正确服务 https://domain/index.html
但没有子文件夹引用,例如 https://domain/folder/
将工作。在将 CF 分配连接到 S3 存储桶时,不要使用 Cloudfront 中的下拉菜单也很重要。您需要使用 S3 静态站点的 URL。
关于amazon-web-services - 如何使用 S3/Cloudfront 在子文件夹中提供 index.html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59634922/