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

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

问题描述

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



我还需要知道如何在没有 www 的情况下设置域以解析到应用程序。



此处是我当前的DNS设置:

  $ TTL 86400 
@ IN SOA ns1.first-ns.de。 postmaster.robot.first-ns.de。 (
2013041500;序列
14400;刷新
1800;重试
604800;到期
86400); IN NS robotns3.second-ns.com中的最低


@ IN NS robotns2.second-ns.de。
@ IN NS ns1.first-ns.de。

@ IN A 88.198.38.XXX
本地主机IN A 127.0.0.1
邮件IN A 88.198.38.XXX
ftp IN CNAME www
imap IN CNAME www
回送CNAME localhost
pop IN CNAME www
中继IN CNAME www
smtp IN CNAME www
www IN CNAME appname.herokuapp.com。
@ IN MX 10邮件

要使用的正确设置是什么? c $ c> example.com 和 www.example.com 是否可以正确指向我的Heroku应用?

解决方案

(注意:根域,基域和apex域都是相同的东西。可互换地用于google-foo。)



传统上,要指向顶点域,您将使用指向您服务器IP的A记录。对于像Heroku这样的云平台,该解决方案无法扩展,也不可行,在该云平台中,多个且频繁更改的后端负责响应请求。



对于子域(例如 www.example.com ),则可以使用指向 your-app-name.herokuapp.com 的CNAME记录。从那里开始,Heroku管理 your-app-name.herokuapp.com 后面的动态A记录,以便它们始终是最新的。不幸的是,DNS规范不允许区域顶部(基础域)上的CNAME记录。 (例如,MX记录会因为先跟随CNAME到达目标而中断。)



返回到根域,简单而通用的解决方案是不使用它们完全没有作为备用措施,某些DNS提供商会为您设置HTTP重定向。在这种情况下,请进行设置,以使 example.com 是HTTP重定向到 www.example.com 。 / p>

一些DNS提供商提出了自定义解决方案,该解决方案允许区域顶点上的CNAME行为。据我所知,我们有 DNSimple的ALIAS记录 DNS Made Easy的ANAME记录



使用它们,您可以将记录设置为(使用zonefile表示法,甚至可能会在其Web用户界面上执行此操作):

  @别名your-app-name.herokuapp.com。 
www IN CNAME your-app-name.herokuapp.com。

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



另请参见:





备注:




  • Amazon的Route 53也具有ALIAS记录类型,但由于它只能在AWS中指向而受到一定的限制。目前,我不建议将其用于Heroku设置。


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



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

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

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

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

解决方案

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

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.

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.)

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.

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.

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.

See also:

Remarks:

  • 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.

  • 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天全站免登陆