Fix 'Too many redirects' after enabling Cloudflare proxy

By

Learn how to fix the Too many redirects error after enabling the Cloudflare proxy, by switching SSL/TLS from Flexible to Full or Full (strict).

~~~

I had an Astro site on Railway and since I manage my DNS using Cloudflare, I figured I could take advantage of everything Cloudflare offers if I proxy the requests through it, instead of just using it as a DNS.

I changed my CNAME record that points to the Railway app from “DNS only” to “Proxied” but the app was not served any more by the browser, with an error saying “Too many redirects”.

The reason is that when Cloudflare talks to your origin over plain HTTP, while the origin automatically redirects HTTP to HTTPS, you get an infinite redirect loop.

That happens with the Flexible encryption mode: visitors talk HTTPS to Cloudflare, Cloudflare talks HTTP to the origin. Flexible was the default when I hit this. Today the default is Automatic SSL/TLS, which probes your origin and picks the safest mode it supports. Cloudflare is still rolling it out, so some zones only show the Custom SSL/TLS options, and Flexible is one of them.

The problem was well documented on Cloudflare’s docs.

The fix is to open the SSL/TLS settings for that domain and switch the encryption mode from Flexible to Full, or Full (strict) if the origin has a valid certificate. With Full, Cloudflare talks HTTPS to the origin too, so the loop stops.

Cloudflare dashboard SSL/TLS settings showing encryption mode options with Full mode selected

Then everything worked as expected.

Tagged: Services · All topics

Want me to talk about your product? You can sponsor this site.

~~~

Related posts about services: