Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku custom domains on Cloudflare: Too many redirects

Objectives

  • Run https://rapid.essbap.org through Cloudflare.
  • This should map to https://ebcc-rrn.herokuapp.com (Rails app)
  • However, I get "too many redirects" pages, e.g.

enter image description here

  • Have done this successfully before on other Heroku apps, using steps below
  • What am I missing?

What I did

  • Purchased essbap.org through Godaddy.
  • Imported DNS to Cloudflare.
  • Inserted Cloudflare name servers at Godaddy.
  • Removed zone records from Godaddy.

Cloudflare:

  • Inserted CNAME record rapid to point to ebcc-rrn.herokuapp.com
  • On Heroku: added custom domain rapid.essbap.org to ebcc-rrn.herokuapp.com

Heroku:

heroku domains:add rapid.essbap.org

=== ebcc-rrn Heroku Domain
ebcc-rrn.herokuapp.com

=== ebcc-rrn Custom Domains
Domain Name       DNS Target
----------------  ----------------------
rapid.essbap.org  ebcc-rrn.herokuapp.com 

$ host rapid.essbap.org 
rapid.essbap.org has address 104.27.162.137 
rapid.essbap.org has address 104.27.163.137

Cloudflare settings

enter image description here

JUST ADDED:

Running curl

When I run curl against another Heroku custom domain app that I know works, it looks like:

$ curl -I some.custom_app.com
HTTP/1.1 301 Moved Permanently
Location: https://some.custom_app.com/

# since I'm using force_ssl on Rails, we expect to be directed to https://

$ curl -I https://some.custom_app.com/
HTTP/1.1 200 OK

Similar behaviour for ebcc-rrn.herokuapp.com (the Herokuapp we want rapid.essbap.org to be an alias for). A 301 then 200.

But when I run curl against rapid.essbap.org, I get:

$ curl -I rapid.essbap.org
HTTP/1.1 301 Moved Permanently
Location: https://rapid.essbap.org/

# since I'm using force_ssl on Rails, we expect to be directed to https://

$ curl -I https://rapid.essbap.org
HTTP/1.1 301 Moved Permanently
Location: https://rapid.essbap.org/

We get a 301 instead of a 200 in the second case. Am not sure why the 301 is being generated. Does not happen in dev or with ebcc-rrn.herokuapp.com.

What am I missing?

like image 352
Daniel May Avatar asked Jul 30 '15 10:07

Daniel May


People also ask

How do I fix too many redirects Cloudflare?

Too Many Redirects If you're receiving the ERR_TOO_MANY_REDIRECTS error when accessing your HTTPS enabled site that is being proxied through Cloudflare, it's likely that you have SSL set to Flexible. This should be set to Full (strict), which will ensure connections to your site are fully encrypted end-to-end.

Does Heroku use Cloudflare?

You can set up your Heroku app in Cloudflare using a secure connection. This process requires configuring two CNAME DNS records and enabling Cloudflare SSL.

What DNS does Heroku use?

Heroku DNS uses DNSSEC to authenticate requests to all herokuapp.com and herokudns.com domains. DNSSEC is a security system that gives DNS servers the ability to verify that the information they receive is reliable.

How do I redirect a non www Heroku?

Go to the record editor and two DNS records, one for each host name, pointing to the Heroku SSL endpoint: Add an ALIAS record to point example.com to Heroku. Leave the Name of the record empty and set the Content field to the SSL endpoint example.com.herokudns.com. Add a CNAME record to point www.example.com to Heroku.


2 Answers

Im my case setting Crypto -> SSL Flexible to Full did the trick.

like image 137
chrisby Avatar answered Sep 23 '22 02:09

chrisby


I experienced the same issue on a site recently, also using Heroku and Cloudflare and SSL.

In our case, the solution was that we had to set the SSL option in Cloudflare under Crypto > SSL to Flexible. We had it on Full, which was causing the site to try to use CloudFlare's SSL certificate. It didn't work with the SSL option set to Off.

like image 38
stephen.hanson Avatar answered Sep 24 '22 02:09

stephen.hanson