Custom root domain on Heroku

2020-05-20 09:41发布

I have a domain, example.com, that I want to use for my rails-app that resides at example.herokuapp.com and I'm pretty confused how to go about to do this.

Heroku says

"Zone apex domains (aka "naked", "bare" or "root" domains), e.g., example.com, using conventional DNS A-records are not supported on Heroku." And then they go on explaining workarounds (using ALIAS or ANAME).

I have spent a good hour reading up on the subject (here on SO and elsewhere) but still don't get my head around this.

Are there any alternative ways or explanations on how to acomplish this for "a dummy"?

标签: heroku dns
3条回答
Lonely孤独者°
2楼-- · 2020-05-20 09:46

Found this: http://blog.cloudflare.com/zone-apex-naked-domain-root-domain-cname-supp

CloudFlare provides a whole bunch of other benefits as well. I've been using them for all of my Heroku apps and I'm quite pleased to be honest.

They provide a lot value for free from my experience with them thus far.

查看更多
ゆ 、 Hurt°
3楼-- · 2020-05-20 09:53

I'll take a stab at this as it's a frequent question.

Ok, so assuming you have a domain example.com and you want to use www.example.com to host your site. In traditional hosting you'd probably have a virtual server which has been assigned an IP address, in this case you would use a host record, otherwise known as an A record in DNS control panels to map www.example.com to the IP address. In this case, since you have now set www.example.com to a fixed IP address should that IP address ever change you will need to update your DNS yourself.

Also, with traditional hosting you could have example.com set to the same IP address so www.example.com and example.com would work for naked domains.

Ok, so what's a CNAME record. A CNAME record rather than mapping to an IP address maps the record to another DNS entry. So, www.example CNAME'd to example.herokuapp.com means that Heroku can and may move where example.herokuapp.com is pointing at but you don't have to update anything as you're using an CNAME record and Heroku are managing where example.herokuapp.com is pointing (which can and may be another CNAME or an IP address). The problem with CNAME records is that they CANNOT point to an IP address, which is fine for www.example.com but a problem with example.com. Heroku previously published IP addresses to be used for naked domains but problems ensued when they suffered DDOS attacks and couldn't replace those IPs with new ones as they were published IP addresses. For the new EU region, Heroku ARE NOT publishing IP addresses for use with naked domains.

What several DNS providers (DNSsimple I know is one) have done is add their own ALIAS records to their DNS servers to allow you to use CNAME's with naked domains so both www.example.com and example.com will work as now supported by Heroku. If you DNS provider does not support ALIAS records then it's worth moving the domain to a DNS provider that does support it. DNSsimple also supports redirect records so you can have www.example.com redirect to example.com at the DNS provider level and not at your application layer.

查看更多
家丑人穷心不美
4楼-- · 2020-05-20 10:02

If you look at DNS records specification you'll find no such record as ANAME.

The best way to solve this problem is: Make CNAME entry for www subdomain to your heroku app, and CNAME record for root domain to www subdomain.

  • www.domain.com. 3600 IN CNAME app.herokuapp.com.
  • @ 3600 IN CNAME www.domain.com.

P.S. It works, and do not make you waste money for mystic DNS records

查看更多
登录 后发表回答