SSL in Heroku with a custom domain

2019-08-09 20:36发布

问题:

I'm using PointHQ as a DNS and hosting my domain on Heroku. On default, it looks like Heroku supports https (eg. https://yodel-site.herokuapp.com), but not when you go to my site with https://yodel.co - although it works with just http://.

What do I need to do in order for SSL (https) to work on my custom domain in Heroku? Is it something to configure in my DNS (PointHQ), or do I need to pay heroku for the addon?

Here's what my Heroku custom domains section looks like:

回答1:

You will have to pay Heroku for the add-on, acquire an SSL cert, and install it according to their instructions. Note also that you should probably avoid installing SSL at the apex, and redirect any apex traffic to the subdomain you do choose (e.g. www).

Using CloudFlare is a reasonable approach to avoid paying Heroku's charges, though the certificate that's presented will not be your own. You can make the choice about whether it's worth the money.



回答2:

The simplest and cheapest way is to upgrade from Free to Hobby Dynos, it will cost a maximum of 7$/month for a small app, and actually probably much less because the price is prorated to the time your Dyno will run per month.(https://www.heroku.com/pricing) This is much cheaper than the 20$/month to get the SSL Heroku add-on.

Once you have upgraded your plan from Free to Hobby, things are pretty straightforward:

  • Go to your app on Heroku, go to settings, scroll down to domains and certificates, and add your domain: www.yourdomain.com
  • This will automatically give you a DNS target as such www.yourdomain.com.herokudns.com
  • In your Domain Host:
    • Add a CNAME record using this DNS target, for instance on Godaddy as such: Type: CNAME Name: www. Value: www.yourdomain.com.herokudns.com
    • Add a redirect action from your root domain (yourdomain.com) to www.yourdomain.com

Allow a few hours for the DNS changes to propagate, and you're all set!