How to connect Heroku to Cloudflare

January 03, 2019
I'm making an alternative to DevTools. Click here to check it out.

To connect a Heroku app to Cloudflare, you can follow these steps.

  1. Add Cloudflare’s name servers to your domain registrar.
  2. Wait for the changes to propagate.
  3. Under Cloudflare’s DNS tab, add a CNAME record with a name of www and a value of yourapp.herokuapp.com, where your app is the name of your app.
  4. Under the same tab, add a CNAME record with a name of @ and a value of yourapp.herokuapp.com, where yourapp is the name of your app.
  5. Set up https in the Crypto tab by setting your site to Full (Strict) mode.1
  6. Force all traffic to use https under the Page Rules tab. Create a rule that if a URL matches http://*yoururl.com/* then “Always Use HTTPS”. Save and deploy.

After this, I usually wait a few hours and then everything works. If you have a better method, get in touch!

  1. I’ve seen some people recommend Flexible mode, but I’ve run into occasional problems with it. ↩︎