Cloudflare Redirect Loop

Enabling Cloudflare on my website cause an odd issue, which I didn't expect. While it seemed to work correctly on this website, on Our Bus & Us it was causing a redirect loop. I thought it was a configuration issue, so I rewrote my nginx server configurations 3 or 4 times. Turns out it had to do with having SSL enabled and a server redirect. Let's take a quick look into the problem and solution.

Redirects to HTTPS and WWW

on all of my websites, I have decided that I want to use only SSL and only WWW. This means if you try to visit, you will be redirected to This will happen for any combination of the domain and protocol. HTTPS and WWW are the only valid combination, all others will redirect to it.

This for SEO and management of Analytics, is perfect. However enabling Cloudflare caused this to go into a redirect loop. Making me think that I had screwed up the redirect logic in the nginx configurations. Nope, I just didn't understand how Cloudflare handled SSL Certificates and Private vs Public connections.

Cloudflare Solution

It turns out, Cloudflare while in Flexible SSL wants to communicate to your server via HTTP. If you redirect it to HTTPS it will try to go back to HTTP. This is the redirect loop. to remedy this, change the configuration to Full in the Crypto settings page.