How to connect Heroku to Cloudflare

Connecting your Heroku app to Cloudflare is a piece of cake.

  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) mode1
  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.
  1. I’ve seen some people recommend Flexible mode, but I’ve run into occasional problems with it. ↩︎