Forget it. Instead, use an intermediate DNS provider like DNS Made Easy to set up your DNS routing properly in 15 minutes. No stress, I promise!
Please note: I used DNS Made Easy as my DNS provider, but Heroku also refers to 5 others that could work (DNSimple, easyDNS, PointDNS, CloudFlare, and namecheap).
My objective
I just finished building a simple frontend app for my new company, Tamkeen Initiative, and used Heroku to deploy it live. My business partner had purchased our domain name, tamkeen.in
, from GoDaddy.
I’d like to set up the following four domains to load smoothly without those scary browser warnings:
All domains should work and direct to https://www.tamkeen.in.
Step 1. Setup custom domain names in Heroku before jumping into GoDaddy or DNS Made Easy.
I followed these Heroku instructions for setting up custom domain names.
From my application’s root directory on the command line, I first created the CNAME for www.tamkeen.in
:
heroku domains:add www.tamkeen.in
Next, I created the ANAME for the root domain, tamkeen.in
:
heroku domains:add tamkeen.in
To confirm the setup, I ran the following:
heroku domains
=== tamkeen Heroku Domain
tamkeen.herokuapp.com
=== tamkeen Custom Domains
Domain Name DNS Record Type DNS Target
tamkeen.in ALIAS or ANAME whispering-elk-ABC.herokudns.com
www.tamkeen.in CNAME boiling-depths-ABC.herokudns.com
We can see that I’ve created one ANAME and one CNAME record, each pointing to a separate DNS target on Heroku.
Step 2. Properly handle SSL by using the Automated Certificate Management provided by Heroku for paid dynos.
It's super easy to setup, a single line on the common line:
heroku certs:auto:enable
This will route any HTTP requests to HTTPS without me having to do any manual configuration. Huge plus of paid Heroku accounts.
Step 3. On the DNS Made Easy website, add a new managed domain.
When I added the domain tamkeen.in
, DNS Made Easy gave me the following nameservers:
- ns0.dnsmadeeasy.com
- ns1.dnsmadeeasy.com
- ns2.dnsmadeeasy.com
- ns3.dnsmadeeasy.com
- ns4.dnsmadeeasy.com
Nameservers essentially define your domain’s current DNS provider, and since we'll be using DNS Made Easy instead of GoDaddy as the main DNS provider, these will replace the defaults in GoDaddy.
Step 4. On the GoDaddy domain management page, point the GoDaddy nameservers to the ones provided by DNS Made Easy.
This removes the ability to manage DNS records on GoDaddy, and activates the DNS Made Easy records.
5. Finally, in DNS Made Easy, set the DNS records to point to Heroku.
It was just as the name implies, ridiculously easy. Just as I created two records in Heroku, I had two records in DNS Made Easy:
Type Name Target
ANAME blank whispering-elk-ABC.herokudns.com.
CNAME www boiling-depths-ABC.herokudns.com.
Please note: the period at the end of both targets is required; otherwise DNS Made Easy appends the domain name to them.
This results in the following:
- https://tamkeen.in points to the
whispering-elk
Heroku app - https://www.tamkeen.in points to the
boiling-depths
Heroku app
And because I had already setup SSL certificates using Heroku, HTTP was forwarding to HTTPS, covering both HTTP cases.
Goal accomplished in 15 minutes.
As for my initial attempt at setting this up on GoDaddy…
The steps covered in this section are not recommended. They merely capture why the initial GoDaddy-Heroku setup did not work for all four domains, and therefore the need to use DNS Made Easy as an intermediary.
Takeaway: Using just GoDaddy and Heroku, three out of the four domains worked fine. https://tamkeen.in did not work.
I initially made use of the GoDaddy DNS offerings:
- CNAME records
- URL redirects / forwarding
- A records
I set the CNAME properly as follows:
Type Name Target
CNAME www boiling-depths-ABC.herokudns.com
Unfortunately, I couldn’t set the ANAME provided by Heroku on GoDaddy. Why not?
A records require a static IP address as the target. Setting the target to a URL provided by Heroku is not allowed in GoDaddy. Unfortunately, this doesn’t account for data centers and other platforms like Heroku that dynamically generate IP addresses for customers based on traffic/load.
To circumvent this issue, I tried to use URL redirects / forwarding, which forwarded http://tamkeen.in to http://www.tamkeen.in using a 301 Redirect. Because I set the CNAME on GoDaddy, these two domains now pointed properly to the Tamkeen website on Heroku.
And because I used Heroku to automatically manage my SSL certificates, http://www.tamkeen.in forwarded to https://www.tamkeen.in
Why was https://tamkeen.in not covered?
The reason is explained well in this Heroku help article. It comes down to the fact that URL redirects / forwarding setup in GoDaddy will only work for non-SSL requests, leaving https://tamkeen.in unable to forward to https://www.tamkeen.in
Lesson learned. In the future, I won't be purchasing domains from GoDaddy or any vendor that offers DNS management without support for root domains hosted on platforms utilizing dynamic IPs to manage traffic.