Amazon web services Cloudfront无法正确重定向到https和子域
根据post和文章,应该在S3存储桶前面创建第二个cloudfront发行版,它重定向到另一个存储桶,其中包含静态文件 a使用前端bucket名称为Amazon web services Cloudfront无法正确重定向到https和子域,amazon-web-services,amazon-s3,amazon-cloudfront,amazon-route53,Amazon Web Services,Amazon S3,Amazon Cloudfront,Amazon Route53,根据post和文章,应该在S3存储桶前面创建第二个cloudfront发行版,它重定向到另一个存储桶,其中包含静态文件 a使用前端bucket名称为www.example.com,重定向bucket为example.com。我已根据以下cloudformation模板设置了AWS资源 但是,出现了一些问题:如果我点击example.com,它不会重定向到www.example.com,只有当我点击了网站上的另一个链接时才会重定向到www.example.com。此外,例如,它不加载favicon
www.example.com
,重定向bucket为example.com
。我已根据以下cloudformation模板设置了AWS资源
但是,出现了一些问题:如果我点击example.com,它不会重定向到www.example.com,只有当我点击了网站上的另一个链接时才会重定向到www.example.com。此外,例如,它不加载favicon。被重定向到。它没有重定向到https,找不到webiste
我的AWS设置缺少什么
提到不要设置默认的根对象属性,我没有设置。但也许有什么关系
FrontendBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.frontendBucketName}
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: 404.html
RedirectdBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.redirectBucketName}
AccessControl: PublicRead
WebsiteConfiguration:
RedirectAllRequestsTo:
HostName: ${self:custom.frontendBucketName}
Protocol: https
WebAppCloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: ${self:custom.frontendBucketName}.s3-website.${self:provider.region}.amazonaws.com
Id: Frontend
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: http-only
Enabled: 'true'
Aliases:
- ${self:custom.frontendBucketName}
CustomErrorResponses:
- ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /index.html
DefaultCacheBehavior:
DefaultTTL: 31536000
MaxTTL: 31536000
MinTTL: 31536000
AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
TargetOriginId: Frontend
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
AcmCertificateArn: 'arn:aws:acm:us-east-1:xxxx:certificate/xxxx'
SslSupportMethod: 'sni-only'
RedirectCloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: ${self:custom.redirectBucketName}.s3-website.${self:provider.region}.amazonaws.com
Id: Redirect
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: http-only
Enabled: 'true'
Aliases:
- {self:custom.redirectBucketName}
DefaultCacheBehavior:
DefaultTTL: 31536000
MaxTTL: 31536000
MinTTL: 31536000
AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
TargetOriginId: Redirect
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
ViewerCertificate:
AcmCertificateArn: 'arn:aws:acm:us-east-1:xxxx:certificate/xxxx'
SslSupportMethod: 'sni-only'
DnsRecord:
Type: "AWS::Route53::RecordSet"
Properties:
AliasTarget:
DNSName:
Fn::GetAtt:
- WebAppCloudFrontDistribution
- DomainName
HostedZoneId: XXXXX
HostedZoneId: XXXX
Name: ${self:custom.frontendBucketName}
Type: 'A'
RedirectDnsRecord:
Type: "AWS::Route53::RecordSet"
Properties:
AliasTarget:
DNSName:
Fn::GetAtt:
- RedirectCloudFrontDistribution
- DomainName
HostedZoneId: XXXX
HostedZoneId: XXXX
Name: ${self:custom.redirectBucketName}
Type: 'A'
目前,您有DNS问题,您尚未发布“www.example.com”的DNS记录 您有DNS for example.com-->CloudFront,但不适用于www.example.com,即使您已将www.example.com添加到CloudFront CNMAE/Alternative字段,但当客户端获得一个带有新位置的301/302并看到主机中的更改时,它会再次解析它 curl-I——解析www.example.com:443:13.249.210.66 HTTP/1.1200ok 内容类型:text/html 内容长度:80232 连接:保持活力 日期:2019年6月23日星期日10:07:43 GMT 最后修改:2019年6月21日星期五07:21:38 GMT ETag:“8d536768b2173a7f3869f4178f75b331” 服务器:亚马逊3 X-Cache:cloudfront未命中 Via:1.1 7db8064d915149cac923df11147875f9.cloudfront.net(cloudfront) X-Amz-Cf-Pop:BLR50-C3 X-Amz-Cf-Id:wOpVoz1gVlxYDBORSfGr9fmt8L-Q6vhWyEm1XPgJVQy-sbes9HTuuQ==
您只需在Route53中为www.example.com创建一个别名记录。从您的描述中不清楚您的意思:“如果我点击example.com,它不会重定向到www.example.com,只有在我单击网站上的另一个链接时。”您能提供域名吗?诊断起来应该足够简单,但根据目前已知的信息,它并不明显。您肯定不需要默认的根对象。是的,这是因为您已将缓存行为设置为将HTTP重定向到https,您将看到两个重定向,首先是cloudfront将HTTP重定向到https,然后s3将其重定向到www。如果不需要两个重定向,您可以设置cloudfront分发(surfquipment.com)在http和https上提供服务,而不是在缓存中重定向行为。我想我理解这个问题,但不知道在上面定义的我的
RedirectCloudFrontDistribution
中要更改什么?您需要设置ViewerProtocolPolicy:允许使用CNAME-surfquipment.com进行所有分发。