nginx.ccWeb server troubleshooting desk
Home / Errors / 3xx
3xx

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

  1. Cloudflare SSL mode Flexible: CDN fetches over HTTP, nginx 301s to HTTPS, CDN fetches over HTTP again…
  2. Both www→apex and apex→www exist (nginx one way, the app or CDN rule the other).
  3. WordPress siteurl disagrees with nginx; or X-Forwarded-Proto is missing so the app thinks it is HTTP and redirects again.
  4. The try_files fallback file does not exist, causing an internal redirect cycle.

Diagnosis commands

Print the whole redirect chain
#curl -sIL --max-redirs 10 http://example.com | grep -iE '^(HTTP|location)'
See the origin's own redirect, bypassing the CDN
#curl -sI -H 'Host: example.com' http://127.0.0.1/
See where the redirect chain loops
#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

Sponsored slot (empty)
VPS / CDN recommendations may appear here later, labelled as affiliate links. There are no referral links today.