How to add custom domain to Heroku App

in #heroku5 years ago (edited)

In order for your Heroku app to be available on your custom domain like www.yourdomain.com ( rather than domains like https://fierce-forest-92184.herokuapp.com/ ), you need to point your custom domain to your Heroku app URL. To achieve this you need to add your custom domain to Heroku which will give you a DNS target domain. The DNS target domain can then be added to your domain hosting sites CNAME. And this will make your app available at www.yourdomain.com

Steps:
1-Go to https://dashboard.heroku.com
2-Click on your app name and then click on Settings
3-Then click on add domain
4-Add your domain and click save.

image.png

Then you will see your domain with DNS target added. e.g. www.yourdomain.com.herokudns.com

image.png

5-Now add the DNS target created above ( without www ) e.g. yourdomain.com.herokudns.com to your DNS CName record on your dashboard panel of the site where you have purchased your domain from ( e.g. Godaddy ). Select a custom value to 600secs or less in TTL

image.png

6-Now go to Heroku CLI on your terminal and run the below commands.

heroku login
host www.yourdomain.com

Then run below command

heroku domains:add www.yourdomain.com
 
// Below command will keep waiting and result in success once the domain is added
heroku domains:wait 'yourdomain.com' // this command
Your Heroku application will now be available on www.yourdomain.com

Your Heroku application will now be available on www.yourdomain.com

You can read more here for other resources - https://devcenter.heroku.com/articles/custom-domains