amazon-web-services - 如何使用 S3/Cloudfront 在子文件夹中提供 index.html?

标签 amazon-web-services amazon-s3 amazon-cloudfront static-site

有一个叫 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 :

  • Serving index pages from a non-root location via CloudFront
  • Serving index pages from a non-root location via CloudFront (now unavailable)
  • Implementing Default Indexes in CloudFront Origins Using Lambda@Edge

  • 配置 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/

    相关文章:

    amazon-web-services - AWS cloudformation 嵌套堆栈因模板 URL 失败

    ruby-on-rails - 将 CSV 流从 Ruby 上传到 S3

    python - 使用 pyspark : [java. lang.IllegalArgumentException 从 S3 服务器读取时出错]

    aws-cloudformation - 创建仅接受无服务器签名 URL 的 CloudFront 分配

    authentication - Server 2012 本地共享 - 无法使用\\IP 访问,但可以通过\\localhost 工作

    python - 在内存中SQLite3共享数据库python

    amazon-web-services - 用 ESP8266 连接手机

    amazon-s3 - 在 AWS 上托管用户上传的视频的最佳方式

    amazon-ec2 - 从 CloudFront 到服务器的字体 CORS 问题

    amazon-web-services - 如何禁用 AWS CloudFront 中的目录列表?