Amazon web services 托管在S3和Cloudfront根页面上的静态站点路由到www.example.com/index.html,而不是www.example.com

Amazon web services 托管在S3和Cloudfront根页面上的静态站点路由到www.example.com/index.html,而不是www.example.com,amazon-web-services,amazon-s3,dns,amazon-cloudfront,Amazon Web Services,Amazon S3,Dns,Amazon Cloudfront,我在AmazonS3和Cloudfront上有一个静态站点。目前,当我访问我的站点www.example.com时,我得到一个403。只有当我进入www.example.com/index.html时,我才能真正访问我的网站。我期望的行为是,当我访问www.example.com时,我看到了我在访问www.example.com/index.html时看到的内容 我已经建立了一个bucket,我们可以称之为example.com,它包含我网站的所有信息。我还有另一个bucket(www.exam

我在AmazonS3和Cloudfront上有一个静态站点。目前,当我访问我的站点www.example.com时,我得到一个403。只有当我进入www.example.com/index.html时,我才能真正访问我的网站。我期望的行为是,当我访问www.example.com时,我看到了我在访问www.example.com/index.html时看到的内容

我已经建立了一个bucket,我们可以称之为example.com,它包含我网站的所有信息。我还有另一个bucket(www.example.com)重定向到example.com

我的域指向Cloudfront,在这里我有一个Cloudfront域集。我想这就是问题所在。我必须从这个域转到/index.html才能真正看到这个站点

我如何设置它,以便在我访问www.example.com时,可以看到www.example.com/index.html上当前存在的内容


我已经将index.html设置为我的bucket的索引文档。

当您为静态网站托管(有或没有CloudFront)设置S3 bucket时,您可以使用索引文档配置该bucket。当客户端发出目录请求时,索引文档被发送到客户端

例如,您希望在客户机转到
www.example.com
时提供
www.example.com/index.html

为此,请将
index.html
设置为bucket的索引文档


请参阅步骤1,子步骤3(b)。

在CloudFront常规配置设置中,确保将默认根对象设置为index.html。作为最佳实践,您应该使用源访问标识符来确保您的对象仅通过CloudFront提供服务


还要确保您的源代码已正确设置为S3存储桶和包含站点的文件夹(如果适用)。

CloudFront的默认根对象仅适用于域的根。所以请求
https://example.com
将从S3提供
/index.html
,但请求
https://example.com/about-us
将只需404(或403,取决于权限)

如果您想从任何目录提供
index.html
,则需要部署Lambda@Edge用于原始请求的函数。接下来,您需要的函数体(Node.js 8.10)是:


嘿谢谢你的帮助。我已经这样做了,并利用了这一资源。我将
index.html
设置为我的bucket的索引文档。你认为我还能做些什么来解决这个问题吗?@maecapozzi有不同的症状,但听起来和这里的问题一样:
exports.handler = (event, context, callback) => {
  const { request }  = event.Records[0].cf;
  const parts        = request.uri.split('/');
  const lastPart     = parts[parts.length - 1];
  const hasExtension = lastPart.includes('.');

  if (!hasExtension) {
    const newURI = request.uri.replace(/\/?$/, '/index.html');
    request.uri = newURI;
  }

  return callback(null, request);
};