简体   繁体   English

Amazon S3静态网络托管无法与自定义域名一起使用(点号)

[英]Amazon S3 static web hosting not working with custom domain name (dot issue)

I followed the instruction on S3 doc to host a static website there. 我按照S3文档上的说明在此处托管了一个静态网站。 Everything works with the domain name provided by S3. 一切都可以使用S3提供的域名。 I can access "examplebucket.s3-website-us-east-1.amazonaws.com" 我可以访问“ examplebucket.s3-website-us-east-1.amazonaws.com”

However, when I forward my own custom domain name, the domain name provider added a dot at the very end of my domain, then it's like I'm accessing "examplebucket.s3-website-us-east-1.amazonaws.com.", this won't work because Amazon thinks you're accessing a different address. 但是,当我转发自己的自定义域名时,域名提供商会在我域名的末尾添加一个点,这就像我正在访问“ examplebucket.s3-website-us-east-1.amazonaws.com”。 ”,这将无法正常工作,因为亚马逊认为您正在访问其他地址。 And then give me 404 error. 然后给我404错误。

Is there any workaround for this? 有什么解决方法吗? or any place I should set up in S3? 还是我应该在S3中建立的任何地方?

I know this is too late for the original question but there may be more people with the same issues (me last week). 我知道对于最初的问题来说为时已晚,但可能会有更多的人遇到同样的问题(上周是我)。

I was having the same issue while trying to create a route in route53 with CloudFormation. 尝试使用CloudFormation在route53中创建路由时遇到相同的问题。 I was trying to redirect my domain www.example.com to example-bucket.s3-website-eu-west-1.amazonaws.com . 我试图将我的域名www.example.com重定向到example-bucket.s3-website-eu-west-1.amazonaws.com

It turns out you cannot redirect to an arbitrary bucket. 事实证明,您无法重定向到任意存储桶。 The bucket name must be the same as the domain you're trying to alias. 存储桶名称必须与您要使用别名的域相同。 So if you want to redirect www.example.com , your bucket name must be www.example.com and the URL must be www.example.com.s3-website-eu-west-1.amazonaws.com . 因此,如果您要重定向www.example.com ,则存储桶名称必须为www.example.com ,而URL必须为www.example.com.s3-website-eu-west-1.amazonaws.com

Moreover cloudformation has a weird syntax. 此外,cloudformation的语法很奇怪。 Cloudformation doesn't need the name of the bucket (it already knows it). Cloudformation不需要存储桶的名称(它已经知道了)。 It only needs the endpoint. 它只需要端点。

So instead of using something like 所以不要使用类似

"AliasTarget": {
               "DNSName" : "example-bucket.s3-website-eu-west-1.amazonaws.com",
               "HostedZoneId" : "<zoneID>"
             },

you need 你需要

"AliasTarget": {
               "DNSName" : "s3-website-eu-west-1.amazonaws.com",
               "HostedZoneId" : "<zoneID>"
             },

And route53 where to redirect because the name of the route must be the same as the name of the bucket. 以及route53重定向到的地方,因为路由的名称必须与存储桶的名称相同。

Related question https://stackoverflow.com/a/5048129/54256 相关问题https://stackoverflow.com/a/5048129/54256

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM