Configure Cloudflare and Heroku over HTTPS
Last updated Apr 23, 2026
Overview
Heroku is a cloud PaaS that supports several pre-configured programming languages. Heroku deals with all your infrastructure so you can focus on your application without having to work at the command line.
This article describes how to configure Heroku with Cloudflare to serve your traffic over HTTPS. For this article, we'll assume that you already have an active domain on Cloudflare, as well as a running Heroku app.
Step 1 - Add a custom domain to your Heroku app
Follow Heroku's instructions: Custom Domain Names for Apps ↗︎.
Step 2 - Add a subdomain in Cloudflare DNS
Below, you will need to add DNS records for a subdomain and the apex domain (also known as "root domain"). Learn how to Managing DNS records in Cloudflare.
Step 2a - Add a subdomain
In the Cloudflare dashboard, go to the DNS Records page.
Add a 'www' CNAME record that points to the custom domain (also known as DNS target) that you obtained in Step 1 above for your subdomain.
| Type | Name | Target | Proxy status |
|---|---|---|---|
CNAME |
www |
{example-domain}.herokudns.com |
Proxied |
Step 2b - Add your root domain
Adding a root or apex domain on Heroku also requires using a CNAME record pointed from your root. You cannot use A records on Heroku because no IP addresses are exposed for Heroku users to use.
Fortunately, Cloudflare offers CNAME flattening to resolve requests for your root domain.
Add a CNAME record for your root and point it to DNS target you obtained in Step 1 above for your domain.
| Type | Name | Target | Proxy status |
|---|---|---|---|
CNAME |
@ |
{example-domain}.herokudns.com |
Proxied |
Step 3 - Confirm that your domain is routed through Cloudflare
The easiest way to confirm that Cloudflare is working for your domain is to issue a cURL command.
curl -I www.example.com
HTTP/1.1 200 OK
Date: Tue, 23 Jan 2018 18:51:30 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Cache-Control: public, max-age=0
Last-Modified: Mon, 31 Dec 1979 04:08:00 GMT
X-Powered-By: Express
Server: cloudflare
CF-RAY: 3e1cf1d936f28c52-SFO-DOG
You can identify Cloudflare-proxied requests by the CF-Ray response header. If either of these two are present, your requests are being proxied by Cloudflare accordingly.
You can repeat the above cURL command for any of the subdomains that you have configured within your DNS settings.
Step 4 - Configure your domain for SSL
Step 4a - Enable SSL
Cloudflare provides a SANs wildcard certificate with all paid plans, and a SNI wildcard certificate with the Free plan. Full details on SSL can be found here ↗︎.
If you don't know what this means, navigate to the Overview tab of the SSL/TLS app in your Cloudflare dashboard. Select Flexible mode to serve your site over HTTPS to all public visitors.
Once the certificate status changes to • Active Certificate, incoming traffic will be served to your site over HTTPS. Visitors will see HTTPS prefixed to your domain name in the browser bar.
Step 4b - Force all traffic over HTTPS
To ensure all traffic to your site is encrypted, Cloudflare lets you force an automatic HTTPS redirect. To configure this, refer to Always Use HTTPS.
You can then use a cURL command to verify that all requests are being forced over HTTPS.
curl -I -L example.com
HTTP/1.1 301 Moved Permanently
Date: Tue, 23 Jan 2018 23:17:44 GMT
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Wed, 24 Jan 2018 00:17:44 GMT
Location: https://example.com/
Server: cloudflare
CF-RAY: 3e1e77d5c42b8c52-SFO-DOG
If SSL was not working for your domain (for example, your SSL certificate has not yet been issued), you would see a 525 or 526 HTTP response after the redirect.
Please note that the issuing of a Universal SSL certificate typically takes up to 24 hours. Our paid SSL certificates issue within 10-15 minutes.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/support/third-party-software/others/configure-cloudflare-and-heroku-over-https/#page","headline":"Configure Cloudflare and Heroku over HTTPS","description":"Set up Cloudflare with Heroku for HTTPS traffic.","url":"https://developers.cloudflare.com/support/third-party-software/others/configure-cloudflare-and-heroku-over-https/","inLanguage":"en","image":"https://developers.cloudflare.com/support/third-party-software/others/configure-cloudflare-and-heroku-over-https/og.png?v=3bfc7c2d0e3ad431","dateModified":"2026-04-23","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Lower Azure egress costs using Microsoft Routing Preference. title: Reduce data transfer (egress costs) between Azure and Cloudflare image: https://developers.cloudflare.com/support/third-party-software/others/reduce-data-transfer-egress-costs-between-azure-and-cloudflare/og.png?v=ee6a130e5045ff22
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/support/llms.txt
Use this file to discover all available pages before exploring further.
Docs