Custom root domain on Heroku

10,565

Solution 1

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.

Solution 2

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.

Share:
10,565
Fellow Stranger
Author by

Fellow Stranger

Updated on June 04, 2022

Comments

  • Fellow Stranger
    Fellow Stranger almost 2 years

    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"?

  • Michael J. Calkins
    Michael J. Calkins over 10 years
    Mediatemple doesn't call this anything special just select CNAME for www. and the root records.
  • Simone
    Simone about 10 years
    Worth adding that CloudFlare now supports CNAME flattening to present a CNAME as an A record. support.cloudflare.com/hc/en-us/articles/…
  • Thomas Walther
    Thomas Walther about 9 years
    If you use CNAME for a root domain on MediaTemple, MX records on the root domain won't work anymore - in other words, you won't get any emails.