ERR_TOO_MANY_REDIRECTS with nginx: how to fix
Short answer
“Too many redirects” is most often a CDN fetching your origin over HTTP while the origin redirects HTTP to HTTPS, forever. Next come www↔apex ping-pong and the app and nginx both redirecting.
Most common cause: Cloudflare SSL mode Flexible: CDN fetches over HTTP, nginx 301s to HTTPS, CDN fetches over HTTP again…
Try this first: Redirect once, on port 80 only
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}Last verified: · against the official docs listed below · Sources
Typical log lines
rewrite or internal redirection cycle while internally redirecting to "/index.html"
Common causes
- Cloudflare SSL mode Flexible: CDN fetches over HTTP, nginx 301s to HTTPS, CDN fetches over HTTP again…
- Both www→apex and apex→www exist (nginx one way, the app or CDN rule the other).
- WordPress siteurl disagrees with nginx; or X-Forwarded-Proto is missing so the app thinks it is HTTP and redirects again.
- The try_files fallback file does not exist, causing an internal redirect cycle.
Diagnosis commands
curl -sIL --max-redirs 10 http://example.com | grep -iE '^(HTTP|location)'curl -sI -H 'Host: example.com' http://127.0.0.1/curl -sIL --max-redirs 10 https://example.com/ | grep -iE '^(HTTP|location)'Fix configs
Redirect once, on port 80 only
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}Tell the backend the real scheme
proxy_set_header X-Forwarded-Proto $scheme; # behind Cloudflare with SSL=Full, $scheme is https
Cloudflare setting
# SSL/TLS → Overview → set the encryption mode to Full (strict) # the origin needs a valid certificate (Cloudflare Origin CA works)
Run nginx -t first, then systemctl reload nginx.
Key facts and sources
- Cloudflare's Flexible mode connects to the origin over HTTP; an origin that redirects HTTP to HTTPS then loops. [developers.cloudflare.com]
- return 301 / 302 stops processing and sends the redirect. [nginx.org]
Checked against the linked pages on 2026-11-14; the official docs win if a newer nginx changes them.
FAQ
Does clearing the browser cache help?
301s are cached, so after fixing try a private window. The root cause still has to be fixed server-side.
Fixed it, but the browser still loops?
Browsers cache 301 redirects, so the old one may linger. Verify in a private window or with curl -I, and clear the site's cache and cookies if needed.
Fix it with a tool
Related errors
VPS / CDN recommendations may appear here later, labelled as affiliate links. There are no referral links today.