如何为指向 Heroku 应用程序的顶级域(无 www)设置 DNS? [英] How do I set up DNS for an apex domain (no www) pointing to a Heroku app?

查看:17
本文介绍了如何为指向 Heroku 应用程序的顶级域(无 www)设置 DNS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Heroku 应用中添加了一个自定义域,它可以与 www.domain.com 一起使用.

I already added a custom domain to my Heroku app and it works with www.domain.com.

我也需要知道如何在没有 www 的情况下设置域来解析应用程序.

I need to know how to set up the domain without www to resolve to the app, too.

这是我当前的 DNS 设置:

Here are my current DNS settings:

$TTL 86400
@   IN SOA ns1.first-ns.de. postmaster.robot.first-ns.de. (
    2013041500   ; serial
    14400        ; refresh
    1800         ; retry
    604800       ; expire
    86400 )      ; minimum

@                        IN NS      robotns3.second-ns.com.
@                        IN NS      robotns2.second-ns.de.
@                        IN NS      ns1.first-ns.de.

@                        IN A       88.198.38.XXX
localhost                IN A       127.0.0.1
mail                     IN A       88.198.38.XXX
ftp                      IN CNAME   www
imap                     IN CNAME   www
loopback                 IN CNAME   localhost
pop                      IN CNAME   www
relay                    IN CNAME   www
smtp                     IN CNAME   www
www                      IN CNAME   appname.herokuapp.com.
@                        IN MX 10   mail

要使用哪些正确设置才能使 example.comwww.example.com 正确指向我的 Heroku 应用程序?

What are the correct settings to use so that both example.com and www.example.com would point correctly to my Heroku app?

推荐答案

(注意:root、base、apex 域都是一样的.google-foo 可以互换使用.)

(Note: root, base, apex domains are all the same thing. Using interchangeably for google-foo.)

传统上,要指向您的顶级域,您会使用指向服务器 IP 的 A 记录.此解决方案无法扩展,也不适用于 Heroku 这样的云平台,在这种平台上,多个且经常变化的后端负责响应请求.

Traditionally, to point your apex domain you'd use an A record pointing to your server's IP. This solution doesn't scale and isn't viable for a cloud platform like Heroku, where multiple and frequently changing backends are responsible for responding to requests.

对于子域(例如 www.example.com),您可以使用指向 your-app-name.herokuapp.com 的 CNAME 记录.从那时起,Heroku 管理 your-app-name.herokuapp.com 背后的动态 A 记录,以便它们始终是最新的.不幸的是,DNS 规范不允许在区域顶点(基本域)上进行 CNAME 记录.(例如,MX 记录会中断,因为 CNAME 将首先跟随其目标.)

For subdomains (like www.example.com) you can use CNAME records pointing to your-app-name.herokuapp.com. From there on, Heroku manages the dynamic A records behind your-app-name.herokuapp.com so that they're always up-to-date. Unfortunately, the DNS specification does not allow CNAME records on the zone apex (the base domain). (For example, MX records would break as the CNAME would be followed to its target first.)

回到根域,简单而通用的解决方案是根本不使用它们.作为后备措施,一些 DNS 提供商提供为您设置 HTTP 重定向.在这种情况下,请将其设置为 example.com 是到 www.example.com 的 HTTP 重定向.

Back to root domains, the simple and generic solution is to not use them at all. As a fallback measure, some DNS providers offer to setup an HTTP redirect for you. In that case, set it up so that example.com is an HTTP redirect to www.example.com.

一些 DNS 提供商提出了自定义解决方案,允许在区域顶点上进行类似 CNAME 的行为.据我所知,我们有 DNSimple 的别名记录DNS Made Easy 的 ANAME 记录;两者的行为相似.

Some DNS providers have come forward with custom solutions that allow CNAME-like behavior on the zone apex. To my knowledge, we have DNSimple's ALIAS record and DNS Made Easy's ANAME record; both behave similarly.

使用这些,您可以将记录设置为(使用区域文件表示法,即使您可能会在他们的网络用户界面上执行此操作):

Using those, you could setup your records as (using zonefile notation, even tho you'll probably do this on their web user interface):

@   IN ALIAS your-app-name.herokuapp.com.
www IN CNAME your-app-name.herokuapp.com.

记住 @ 这里是根域 (example.com) 的简写.另请注意,尾随点很重要,无论是在区域文件中还是在某些网络用户界面中.

Remember @ here is a shorthand for the root domain (example.com). Also mind you that the trailing dots are important, both in zonefiles, and some web user interfaces.

  • Amazon 的 Route 53 也有一个 ALIAS 记录类型,但它有一定的局限性,因为它只能指向 AWS 内部.目前我不建议在 Heroku 设置中使用它.

  • Amazon's Route 53 also has an ALIAS record type, but it's somewhat limited, in that it only works to point within AWS. At the moment I would not recommend using this for a Heroku setup.

有些人将 DNS 提供商与域名注册商混为一谈,因为与同时提供两者的公司有些重叠.请注意,要将您的 DNS 切换到上述提供商之一,您只需要使用当前的域注册商更新您的名称服务器记录.您无需转移域名注册.

Some people confuse DNS providers with domain name registrars, as there's a bit of overlap with companies offering both. Mind you that to switch your DNS over to one of the aforementioned providers, you only need to update your nameserver records with your current domain registrar. You do not need to transfer your domain registration.

这篇关于如何为指向 Heroku 应用程序的顶级域(无 www)设置 DNS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆