How to set up your own domain in Heroku?

I bought a domain and I need to configure my application that is in Heroku. How to do this?

Author: brasofilo, 2014-05-14

3 answers

To configure the domain of your application, it is directly in the application settings and by accessing the "Domains" section. Looking at the documentation ( custom-domains ). It ensures that requests made to the custom address and pointing to the address of your application in Heroku (xxxxxx.herokuapp.com) are met.

You will have to configure a CNAME or ADDRESS (CNAME is more reliable since your Heroku domain never changes, the IP may change depending on Heroku policy) of the domain you want for xxxxxx.herokuapp.com in your DNS provider.

I just did a test: in the options of "Domain" put only the address without www, for example: nome_do_domino.com. In your DNS provider create a CNAME record of nome_do_domino.com pointing to nome_da_aplicacao.herokuapp.com. In a short time the address becomes accessible.

 2
Author: Wakim, 2014-05-15 01:34:34

The problem is that the "naked domain" (xxx.com.br) cannot be a CNAME. What can be done is 1) Create a CNAME of www.xxx.com.br for nome_da_aplicacao.herokuapp.com 2) put an entry a pointing to 174.129.25.170

This IP is from a service that redirects domains without www To www.domain, more details in this URL:

Http://wwwizer.com/naked-domain-redirect

 0
Author: Rubens Kuhl, 2017-04-12 11:40:23

While using the nome-do-app.herokuapp.com method works, Heroku's ACM (automatic Certificate Manager) will fail and you will not be able to use your domain with an HTTPS session, only HTTP. In order for the ACM not to fail, you will need to use the DNS target .

Since it took me a long time to find a solution and this question was one of those that arose when I Googled, I decided to post What I learned to be able to help those who are lost. In addition, the answers given previously do not solve completely the problem in 2020.

Here I will try to be as complete as possible by doing a step by step, but the direct answer to the question is in Step 4. If the location you purchased the domain supports records type ANAME or ALIAS, you can skip steps 1 and 2.

Step 0: Do I need PointDNS?

It depends . You can instead use the DNS server itself that the case it provides support for records of Type ANAME/ALIAS, for Heroku requires this for root domains. Without this, although you can use www (e.g. https://www.meu-dominio.com), you cannot use the root of your domain (e.g. https://meu-dominio.com). Currently many people no longer type www at the beginning, and although some modern browsers automatically prefix it, you run the risk of your visitor typing and not being able to access your site.

If you only want to register www and do not want to use the PointDNS, Skip to Step 3 .

Step 1: enabling the pointdns add-on

To properly configure ACM along with PointDNS you need to add this add-on in at least one of your apps. Note that, you do not necessarily need to configure PointDNS for the app it is connected to and can direct subdomains to other apps. As a personal experience, I have the add-on in my production app and also use it to set up the domain of staging .

To configure:

  • by UI: enter the resources tab; in the part of add-ons, search for PointDNS in the search field and select the result that has the plan Developer.
  • by CLI: enter the command: heroku addons:create pointdns:developer.

This plan is free and allows 10 records with 10,000 monthly redirects (more than enough for one project personal).

Step 2: modifying the nameservers of the registration location

If you haven't done it yet, no problem, let's do it now.

Before logging into your account from where you registered your domain, see the list of Nameservers in the pointdns app (you will need to be logged in) and choose the 3 that have the best location (at the moment I write they recommend 3). Add these 3 chosen in the list of records with type NS.

Now logging into your account, look for the settings and follow the steps (based on registro.br):

  1. click the domain in the list you want to edit.
  2. in the DNS section, click Alterar Servidores DNS.
  3. put 1 master and 2 slaves with the 3 nameservers you chose in PointDNS.
  4. save everything and, important, wait for at least 2 hours for these changes to propagate .

Step 3: adding a domain in the Heroku

If you haven't done this before, you'll need to add this sim in the app you'll use in Heroku. To add, use:

  • by UI: enter the settings tab; in the part of domains, click Add domain. Enter your domain and click next. Copy the DNS target that will appear, you will need it later.
  • by CLI: enter the command: heroku domains:add www.example-domain.com. Then, type the command heroku domains and copy the DNS target that it will appear, you will need it later.

Obs. 1: the DNS target will be something in the format papagaio-brasileiro-13fqwefrr4r.herokudns.com or something similar ending in .herokudns.com

Obs. 2: remember that meu-dominio.com and www.meu-dominio.com are 2 different records and if you want to cover both user spellings, you will need to register both.

Step 4: adding the DNS targets in PointDNS (valid for any other DNS service)

If you have using PointDNS and you have already gone through Step 3 , probably when accessing the interface you will already see some records written automatically. Although they are valid for accessing the site, they will not work with ACM (automatic Certificate Manager). For this you should use the DNS targets that I said you would need in Step 2 .

  1. to access the PointDNS Dashboard, go to the Heroku UI, the resources tab, and click the add-on of PointDNS.
  2. in the PointDNS Dashboard, click the pencil to edit the record and add the respective DNS target in the target/data field, replacing the one you have there.
  3. you can add new records to other apps if you want to use another subdomain of the same domain. To do this click on add record , select the correct type, put the subdomain and the respective DNS target in the field target / data .
  4. once all modifications are made, wait for at least 2 hours for these changes to propagate.

Note: for domain root (i.e. without the www. in front, only meu-dominio.com) you need compulsorily to use the type ALIAS when setting up the record. DO NOT USE THE CNAME TYPE FOR ROOT DOMAINS. for all other records having subdomain (www, staging, etc), use the type CNAME.

Step 5: ufa... it's over!

Only wait for at least 2 hours for these changes to propagate. It sounds like a beast, but I myself made a lot of mistakes in that part. Once the changes are complete, ACM will automatically validate SSL certificates and you don't have to worry about it anymore.

 0
Author: Daniel Lavedonio de Lima, 2020-05-27 05:11:09