What the Nginx Too Many Redirects Error Means
The “too many redirects” error means the browser followed a chain of redirects that never reached a final page, usually bouncing between HTTP and HTTPS or between two URL forms. Browsers stop after about 20 hops and show the error. This guide explains the causes of a Nginx too many redirects error and the fix for each, starting with the most common one: an SSL mode mismatch between Nginx and Cloudflare.
A redirect loop is easy to recognise in the browser, but the cause is not always in Nginx. The loop can live in Nginx, in the application, in Cloudflare, or in the combination of two layers that disagree about whether the request is secure. The debugging method is the same in every case: follow the redirect chain with curl, find the two URLs that repeat, and ask which layer produces each hop.
curl -IL https://example.com | grep -iE "^(HTTP|location)"
curl -IL http://example.com | grep -iE "^(HTTP|location)"
If the output alternates between the same two URLs, you have found the loop. If it shows a long chain of different URLs, the application is redirecting through a series of pages, which is a different problem with a different fix.
Fix the Cloudflare Flexible SSL Loop
The single most common cause is Cloudflare SSL mode set to Flexible while Nginx redirects HTTP to HTTPS. In Flexible mode, Cloudflare connects to your origin over plain HTTP even when the visitor uses HTTPS. Nginx sees an HTTP request and redirects to HTTPS. Cloudflare receives the redirect, requests the origin over HTTP again, and the loop repeats forever. The fix is to change Cloudflare SSL mode to Full or Full (Strict) so Cloudflare connects to the origin over HTTPS, matching what Nginx expects.
In the Cloudflare dashboard, go to SSL/TLS and set the mode to Full (Strict) if your origin has a valid certificate, or Full if it has a self-signed one. Then confirm the origin really serves HTTPS. The Cloudflare security settings, including SSL modes and firewall rules, are explained in the guide to Cloudflare security settings and SSL modes. A Cloudflare Nginx redirect loop that survives a mode change usually means the origin redirect is cached at the edge, so purge the Cloudflare cache after changing the mode and test in a private browser window.
If you do not use Cloudflare, check for a second redirect layer on the origin itself. A Nginx redirect loop can also come from two server blocks that redirect to each other, for example an HTTP block that redirects to HTTPS and an HTTPS block that redirects back to HTTP because of a copy-paste error. Read both blocks fully instead of assuming the redirect lives in only one of them.
Fix WordPress and Application Redirect Loops
WordPress stores its site URL in the database, and a mismatch between that URL and the address Nginx serves produces a loop. If WordPress thinks the site is at http://example.com while visitors arrive at https://example.com, WordPress redirects to HTTP, Nginx redirects back to HTTPS, and the browser gives up. Check the site URL in the WordPress settings or directly in the database, and make it match the canonical address, including the https:// scheme and the presence or absence of www.
The www versus non-www choice causes the same loop when two layers disagree. If Nginx redirects www to non-www while WordPress redirects non-www to www, the result is a loop even though each redirect looks correct alone. Pick one canonical form and make every layer agree: Nginx, WordPress, and Cloudflare page rules if you use them. The server block pattern for a clean canonical redirect is covered in the guide to setting up Nginx server blocks on Ubuntu 24.04.
Application-level loops also come from plugins. A redirect plugin, an SSL plugin, or a security plugin can each add its own redirect, and two plugins redirecting in opposite directions loop just as reliably as a server misconfiguration. Disable redirect and SSL plugins one at a time and retest after each. If the loop stops, you found the conflicting plugin, and the fix is to keep only one layer in charge of redirects.
Fix Nginx SSL Redirect Mistakes
A Nginx SSL redirect problem also appears when the HTTPS server block itself contains a redirect to HTTPS. This happens when someone copies the HTTP block to create the HTTPS block and forgets to remove the redirect line. The HTTPS block then redirects HTTPS requests to HTTPS, which is a loop of one. The HTTPS block should serve content, not redirect, and only the HTTP block should contain the redirect:
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
# ... ssl_certificate and content configuration, no redirect here
}
After fixing, test with curl and clear the browser cache, because browsers cache 301 redirects aggressively and will keep looping on the old redirect even after the server is fixed. Test in a private window or with curl to avoid that trap. If the site sits behind a proxy, the Nginx reverse proxy setup tutorial explains how X-Forwarded-Proto headers interact with redirects, which matters when the application decides whether to redirect based on the protocol header rather than the real connection. Finally, if you are setting up certificates as part of this fix, the guide to installing a free Let’s Encrypt certificate on Nginx covers the certificate side so the HTTPS block has a valid certificate to serve.