How to set your own domain in Heroku?

Asked

Viewed 4,318 times

4

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

3 answers

2

To configure your application’s domain, it is directly in the application’s settings and accessing the "Domains" section. Looking at the documentation (custom-Domains). It ensures that requests made to the custom address and that points to the address of your application in Heroku (xxxxxx.herokuapp.com) be attended to.

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

I just made a test: in the "Domain" options put only the address without www, for example: nome_do_domino.com. On 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.

  • Oops, beauty @Wakim... I’ll try it here! Thank you.

  • 1

    The problem with the.br record is not having asterisk support on CNAME *.bar.com.br, another alternative is using fixed IP on A but with Heroku, fixed IP is even more complicated, initially only offers by address. As it is?

1

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

Since it took me a long time to find a solution and this question was one of the ones that came up when I Googled, I decided to post what I learned so I could help those who are lost. Moreover, the answers given above do not resolve completely the problem in 2020.

Here I will try to be as complete as possible by taking a step by step, but the direct answer to the question is in Step 4. If the location you purchased the domain has support for Records guy ANAME or ALIAS, can skip steps 1 and 2.

Step 0: I need Pointdns?

Depends. You can use the DNS server itself if it provides support for Records type ANAME/ALIAS, because Heroku requires it for root domains. Without it, although you can use www (ex.: https://www.meu-dominio.com), cannot use root for your domain (eg.: https://meu-dominio.com). Currently many people no longer type the www at the beginning and, although some modern browsers put the prefix automatically, you run the risk of your visitor typing and unable to access your site.

If you just want to register the www and do not want to use Pointdns, skip to the step 3.

Step 1: enabling the Pointdns add-on

To properly configure ACM along with Pointdns you need to add this add-on to at least one of your apps. Note that, not necessarily you need to set up Pointdns for the app it’s 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 configure the staging.

To configure:

  • Through the UI: Enter the tab Resources; on the part of add-ons, search for Pointdns in the search field and select the result that has the plan Developer.
  • By CLI: type the command: heroku addons:create pointdns:developer.

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

Step 2: Modifying registry location nameservers

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

Before logging into your account where you registered your domain, see 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 time of writing they recommend 3). Add these 3 chosen ones to the list of Records like NS.

Now entering your account, browse the settings and follow the steps (based on the.br registry):

  1. Click on the domain from the list you want to edit.
  2. In the DNS section, click Alterar Servidores DNS.
  3. Place 1 master and 2 Slaves with the 3 nameservers you chose on Pointdns.
  4. Save everything and, important, wait for at least 2 hours for these changes to spread.

Step 3: adding a domain to Heroku

If you haven’t already done this before, this yes you need to add in the app you will use in Heroku. To add, use:

  • Through the UI: Enter the tab Settings; on the part of Domains, click on Add Domain. Enter your domain and click next. Copy the target DNS that will appear, you will need it after.
  • By CLI: type the command: heroku domains:add www.example-domain.com. Then type the command heroku domains and copy the target DNS that will appear, you will need it after.

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

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

Step 4: Adding DNS targets in Pointdns (valid for any other DNS service)

If you’ve been using Pointdns and you’ve been through step 3, probably when accessing the interface you will already see some Records automatically written. Although they are valid to access the site, they will not work with ACM (Automatic Certificate Manager). For this you should use the DNS targets I said I would need on step 2.

  1. To access the Pointdns Dashboard, go to the Heroku UI in the tab Resources and click on add-on pointdns.
  2. In the Pointdns Dashboard, click the pencil to edit the record and add the respective DNS target in the field target/date, replacing whatever is there.
  3. You can add new Records for other apps if you want to use another subdomain of the same domain. To do this click Add record, select the correct type, place the subdomain and the respective DNS target in the field target/date.
  4. Once all modifications are made, allow at least 2 hours for these changes to spread.

Obs: For mastery root (that is, without the www. at the front, only meu-dominio.com) you need obligatorily type ALIAS when setting up the record. DO NOT USE CNAME TYPE FOR ROOT DOMAINS. For all the others Records subdomain (www, staging, etc), use the type CNAME.

Step 5: Ufa... over!

Only wait for at least 2 hours for these changes to spread. It looks like a beast, but I made a lot of mistakes in that part. When the changes are complete, ACM will automatically validate SSL certificates and you won’t have to worry about that anymore.

0

The problem is that the "Naked Domain" (xxx.com.br) cannot be a CNAME. What can be done is 1) Create a CNAME from www.xxx.com.br for application.herokuapp.com name_name 2) Place an A entry pointing to 174.129.25.170

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.