我创建了一个 CloudFront 发行版来为静态网站提供服务。 S3是源服务器。
现在,如果我们访问 CloudFront URL,它会重定向到 S3 位置。
d2s18t7gwlicql.cloudfront.net
or
test.telekha.in
在浏览器中显示的是https://telekha-test-www.s3.ap-south-1.amazonaws.com/index.html#/dashboard https://telekha-test-www.s3.ap-south-1.amazonaws.com/index.html#/dashboard
我期待着https://test.telekha.in/#/dashboard https://test.telekha.in/#/dashboard
如果我访问https://test.telekha.in https://test.telekha.in通过卷曲它返回我的index.html
文档
如果我访问http://test.telekha.in http://test.telekha.in通过curl返回
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>CloudFront</center>
</body>
</html>
但在浏览器中,HTTP 和 HTTPS 都重定向到https://telekha-test-www.s3.ap-south-1.amazonaws.com/index.html#/ https://telekha-test-www.s3.ap-south-1.amazonaws.com/index.html#/
请让我知道如何解决这个问题。
快速解决方案
使用 S3 存储桶的区域域名来配置 CloudFront 分配的来源,例如:{bucket-name}.s3.{region}.amazonaws.com
.
解释
根据AWS开发者论坛的讨论:Cloudfront 域重定向到 S3 原始 URL(通过 archive.org) http://web.archive.org/web/20200511224519/https://forums.aws.amazon.com/thread.jspa?threadID=216814,为新创建的 S3 存储桶创建和传播 DNS 记录需要时间。对于在以下位置创建的存储桶,该问题不可见美国东部(弗吉尼亚北部)区域,因为该区域是默认区域(后备区域)。
每个 S3 存储桶有两个域名,一个全局域名,一个区域域名,即:
-
global —
{bucket-name}.s3.amazonaws.com
-
regional —
{bucket-name}.s3.{region}.amazonaws.com
如果您将 CloudFront 分配配置为使用全局域名,您可能会遇到此问题,因为 DNS 配置需要时间。
但是,您可以首先在源配置中使用区域域名来避免此 DNS 问题。
云形成模板
如果您使用的是 CloudFormation,则可以使用RegionalDomainName https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html#RegionalDomainName-fn::getatt的输出属性AWS::S3::Bucket https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html资源:
S3Bucket:
Type: AWS::S3::Bucket
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: !GetAtt S3Bucket.RegionalDomainName
更多信息
另外,我强烈建议您阅读这篇关于 S3 不同路径格式的未来的博客文章:
- Amazon S3 路径弃用计划 – 故事的其余部分 https://aws.amazon.com/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)