将 Amazon CloudFront 指向 A 记录而不是 CNAME
我找到了将我的域的 CNAME
指向 Amazon 的 CloudFront 服务的说明,但理想情况下我想指向根名称(A 记录名称)。例如,example.com 而不是 www.example.com。这可能吗?
I've found instructions to point my domain's CNAME
to Amazon's CloudFront service but ideally I would like to point the root name (A record name). For example, example.com instead of www.example.com. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Route 53 服务将区域顶点(即 example.com)指向 AWS 上的 CloudFront 分配。只需登录您的 CloudFront 分配并将备用域名 (CNAME) 设置为您的域(例如 example.com 和/或 www.example.com)。然后在 Route 53 中,为您的域创建一个托管区域,然后创建一个别名记录,选择 CloudFront 分配作为目标。您还可以为任何子域创建第二个别名记录,例如 www.example.com。注意:您还需要通过域名注册商更改名称服务器。
来自 53 号公路常见问题解答:
有关更多信息,请参阅 AWS 文档:
You can point the zone apex (i.e. example.com) to a CloudFront distribution on AWS using their Route 53 service. Just log into your CloudFront distribution and set the Alternate Domain Names (CNAMEs) to your domain (e.g. example.com and/or www.example.com). Then in Route 53, create a hosted zone for your domain, and then an alias record selecting the CloudFront distribution as the destination. You can also create a second alias record for any sub-domains, such as www.example.com. Note: you'll need to change the name servers with your domain registrar too.
From the Route 53 FAQs:
For more information, see AWSs documentation:
仍然可以使用 A 记录来指向
www.example.com
,但是您必须将其指向 IP 地址,它与“www”或前面的任何其他内容无关或不。CNAME 和 A 记录之间的区别仅在于 CNAME 指向另一个名称,该名称必须依次由 DNS 查找,而 A 记录只需要一次查找并直接指向 IP 地址。
也就是说,您很快就会明白为什么在此类云托管中使用 A 记录可能是一个坏主意或不可能。亚马逊使用多个 IP 地址,您不会预先知道这些 IP 地址是什么。 DNS 更改速度很慢。因此,除非您有一个不会更改的特定 IP 地址,否则使用 A 记录根本不起作用。找到具有固定 IP 地址的托管服务,您就可以使用 A 记录。
在性能或可达性方面,CNAME 和 A 记录之间只有微小的差异。
编辑:
正如 SLAks 指出的那样,似乎最好坚持“旧规则”,为根域名使用 A 记录。但您会发现有时您别无选择,具体取决于您的托管提供商允许您做什么。幸运的是,现在几乎没有什么可以阻止您这样做(使用 CNAME)。
Pointing
www.example.com
can still be done with an A-record, but you have to point it to an IP address then, it has nothing to do with the "www" or anything else in front or not.The difference between CNAMEs and A-Records is only that a CNAME points to another name, which must in turn be looked up by the DNS, whereas an A-record only requires one lookup and is pointed directly to an IP address.
That said, you quickly understand why using A-records with this type of cloud hosting might be a bad idea or impossible. Amazon uses several IP addresses and you won't know up front what IP addresses these are. DNS changes are slow. So, unless you have a specific IP address that does not change, using an A-record simply will not work. Find a hosting offer with a fixed IP address and you can use A-records.
In terms of performance or reachability, there's only a marginal difference between CNAME and A-records.
EDIT:
As SLaks points out, it seems best to stick to "old rules" to use an A-Record for your root domain name. But you'll find that sometimes you will not have a choice, depending on what your hosting provider allows you to do. Luckily, nowadays, there's little if anything that should practically withhold you from doing so (using CNAME).
我们使用cloudfront,并使用route53作为dns。
指向根域的最佳方法是将其设置为 A 记录,然后单击小“别名”滑块。
在新的下拉列表中,选择 cloudfront 作为别名端点。
将出现另一个下拉列表,显示与您管理的区域具有相同根域名的 Cloudfront 存储库。选择它就完成了。
确保在 cloudfront 配置本身中,您拥有裸域的 CNAMES 条目,以及 www 版本域名的第二个条目。
从那里开始,只要您的 Web 服务器设置为接受该域的流量,它就应该可以工作。
We use cloudfront, and we use route53 for dns.
The best way to point the root domain is to set it up as an A record, then click the little "Alias" slider.
In the new dropdowns, choose cloudfront as the alias endpoint.
Another dropdown appears, showing cloudfront repositories that have the same root domain name as the zone you are managing. Select it and you are done.
Make sure that in the cloudfront configuration itself that you have CNAMES entries for both the naked domain, and a second one for the www version of your domain name.
From there it should work as long as your web server is setup to accept traffic for the domain.