Why Cloudflare Proxy Causes Redirect Issues (And How to Fix It)
Troubleshooting redirect loops when using Cloudflare's proxy and how to properly configure SSL settings.
Redirect loops are a common headache when setting up Cloudflare. This usually happens when there's a mismatch between how Cloudflare talks to your server and how your server expects to be talked to.
The Mismatch
If your server is configured to force HTTPS, but Cloudflare is set to "Flexible" SSL, Cloudflare will request your site over HTTP. Your server sees the HTTP request, issues a 301 redirect to HTTPS, and sends it back to Cloudflare. Cloudflare follows the redirect... over HTTP again. Loop.
The Solution: Full (Strict)
Change your Cloudflare SSL/TLS setting to Full (Strict). This ensures that:
- Cloudflare connects to your origin via HTTPS.
- The SSL certificate on your origin is valid.
Verify Your Origin
Ensure your server is listening on port 443 and has a valid certificate (even a Cloudflare Origin CA certificate works perfectly).
server {
listen 443 ssl;
server_name example.com;
# ... ssl config
}By aligning the encryption level between Cloudflare and your origin, you eliminate the redirect loop and improve security.