如何使用 cloudfront 将根域设置为 CNAME 记录?

How can I set the root domain as CNAME record with cloudfront?

我想将我的根域 (abc.example) 指向云端 CNAME 记录 (xxx.cloudfront.net)。但是,GoDaddy 不允许使用 @ 作为主机的 CNAME。

我希望 https://abc.example 能够指向 xxx.cloudfront.net

我该如何更改?

很遗憾,这是不可能的。这是一个 DNS 限制,因为 CNAME 不允许您在区域中多次拥有相同的记录,无论记录类型如何。因此,SOA 和 NS 记录将与之冲突,如果存在 MX 记录也会与之冲突。

您可以将自己的自定义域名重定向到 Amazon CloudFront,但您需要使用 Amazon Route 53 而不是 third-party DNS 服务。

来自Routing Traffic to an Amazon CloudFront Web Distribution by Using Your Domain Name - Amazon Route 53

If you want to use your own domain name, use Amazon Route 53 to create an alias record that points to your CloudFront distribution. An alias record is a Route 53 extension to DNS. It's similar to a CNAME record, but you can create an alias record both for the root domain, such as example.com, and for subdomains, such as www.example.com. (You can create CNAME records only for subdomains.) When Route 53 receives a DNS query that matches the name and type of an alias record, Route 53 responds with the domain name that is associated with your distribution.

步骤是:

  • 在 Amazon Route 53 中使用 A 记录
  • 设置Alias = Yes
  • 别名目标设置为 CloudFront 分配

请注意,如果您希望使用 HTTPS (SSL) 进行分发,则需要执行其他步骤。使用 SNI 是免费的,但专用 IP 地址很昂贵。参见:Custom SSL | Content Delivery Network (CDN), Domain Registration | Amazon CloudFront