我在Amazon S3和Cloudfront上托管了一个静态网站。目前,当我访问我的网站www.example.com时,我得到了403.仅当我访问www.example.com时/index.html我实际上访问了我的网站。我希望的行为是,当我访问www.example.com时,我会看到当我访问www.example.com/index.html时看到的内容。
我已经设置了一个我们可以称之为example.com的存储桶,其中包含我所有网站的信息。我还有另一个桶(www.example.com)重定向到example.com。
我的域指向Cloudfront,我在其中设置了Cloudfront域集。我认为这就是问题所在。我必须从这个域转到/index.html才能真正看到该网站。
如何进行设置,以便在访问www.example.com时,我会看到www.example.com/index.html目前的内容?
我已经将index.html设置为我的存储分析索引文档。
答案 0 :(得分:1)
CloudFront的默认根对象仅适用于您域的根。因此,对2018-11-16 16:04:33.626 DEBUG 3387 --- [ntLoopGroup-2-3] o.s.d.m.core.ReactiveMongoTemplate : find using query: { "symbol" : "BTC" } fields: Document{{}} for class: class nl.reactive.charts.server.domain.CryptoCurrencyRate in collection: cryptoCurrencyRate
2018-11-16 16:04:33.627 DEBUG 3387 --- [ntLoopGroup-2-3] o.s.d.m.core.ReactiveMongoTemplate : find using query: { "symbol" : "ETH" } fields: Document{{}} for class: class nl.reactive.charts.server.domain.CryptoCurrencyRate in collection: cryptoCurrencyRate
2018-11-16 16:04:33.629 DEBUG 3387 --- [ntLoopGroup-2-3] o.s.d.m.core.ReactiveMongoTemplate : find using query: { "symbol" : "XRP" } fields: Document{{}} for class: class nl.reactive.charts.server.domain.CryptoCurrencyRate in collection: cryptoCurrencyRate
的请求将从S3服务到https://example.com
,而对/index.html
的请求将简单地为404(或403,具体取决于权限)。
如果要从任何目录提供https://example.com/about-us
,则需要为原始请求部署Lambda @ Edge函数。遵循this tutorial,您需要的功能主体(Node.js 8.10)为:
index.html
答案 1 :(得分:0)
当您为静态网站托管(使用或不使用CloudFront)设置S3存储桶时,您可以使用索引文档配置存储桶。当客户端发出目录请求时,索引文档将发送到客户端。
例如,您希望在客户转到www.example.com/index.html
时投放www.example.com
。
为此,请将index.html
设置为您的存储分区索引文档。
https://docs.aws.amazon.com/AmazonS3/latest/dev/HostingWebsiteOnS3Setup.html
参见步骤1,子步骤3(b)。
答案 2 :(得分:0)
在CloudFront常规配置设置中,确保将默认根对象设置为index.html。作为最佳实践,您应使用原始访问标识符来确保您的对象仅通过CloudFront提供。
另外,请确保您的来源已正确设置到S3存储桶和包含您网站的文件夹(如果适用)。