Redirect loops happen when two layers keep sending the browser back and forth. The fix is to locate the layer producing each Location header.
Symptoms
- Browser shows too many redirects.
- curl -IL repeats the same URLs or alternates between hosts.
- The loop appears only behind a CDN or reverse proxy.
Likely causes
- HTTPS redirects are configured in both Nginx and CDN with conflicting assumptions.
- www and non-www rules point at each other.
- Application code redirects after Nginx already canonicalized the URL.
Fix steps
- Use curl -IL to list each redirect hop and Location header.
- Keep canonical host redirects in one layer when possible.
- Review server blocks before generic proxy rules and run nginx -t before reload.
Verify the fix
- Run nginx -t.
- Run curl -IL http://example.com/path and https://example.com/path.
- Check CDN rules if the origin works but public traffic loops.
FAQ
Is a redirect loop always an Nginx bug?
No. It may come from CDN, load balancer, application middleware or mixed rules.
Should I use 301 while testing?
Use 302 for uncertain tests, then switch to 301 after behavior is confirmed.
Related tools and guides
Last updated: May 18, 2026