Type | Name | Target | Proxy status |
---|---|---|---|
CNAME | www | {example-domain}.herokudns.com | Proxied |
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.
Follow Heroku's instructions: Custom Domain Names for Apps ↗.
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.
To start, log in to your Cloudflare account, navigate to the DNS app and 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 |
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 |
The easiest way to confirm that Cloudflare is working for your domain is to issue a cURL command.
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.
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 (e.g., visitors will see HTTPS prefixed to your domain name in the browser bar).
To ensure all traffic to your site is encrypted, Cloudflare lets you force an automatic HTTPS redirect. To configure this, consult: How do I redirect all visitors to HTTPS/SSL? ↗
You can then use a cURL command to verify that all requests are being forced over HTTPS.
If SSL was not working for your domain (e.g. 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.