VPS Tutorials
Too many redirects: trace Cloudflare, Nginx and WordPress loops
Trace Location responses, align HTTPS and canonical domains, verify trusted proxy headers and WordPress settings, then test origin, CDN and login separately.

When a site reports ERR_TOO_MANY_REDIRECTS, capture its Location redirect chain before changing settings. HTTP/HTTPS loops, www/apex conflicts and login-session loops require different fixes. Keep existing TLS and application settings while identifying the conflicting rule; reinstalling the VPS does not resolve a redirect policy.
This guide is for Nginx, Cloudflare and WordPress site owners. Replace example.com with your domain. Configuration fragments illustrate where to edit; do not overwrite certificates, document roots or the application's existing configuration. The examples are diagnostic instructions, not results from a newly tested live site.
Run these from your computer or VPS. The first inspects the initial response; the second follows redirects with GET, up to ten times, without printing the response body:
curl -sS -D - -o /dev/null https://example.com/
curl -sS -L --max-redirs 10 -D - -o /dev/null https://example.com/
Check status lines and Location. A curl limit error is useful evidence: raising the limit does not repair the loop. GET is intentional because some applications handle HEAD differently.
| Redirect pattern | Check first | Likely correction |
|---|---|---|
| HTTP → HTTPS → HTTP | CDN origin protocol and origin redirects | Consistent HTTPS and encryption mode |
| Apex domain → www → apex | Canonical domain in CDN, Nginx and application | One final hostname at every layer |
| Same HTTPS URL repeatedly returns 301/302 | Whether the application recognizes external HTTPS | Forwarded headers and trusted proxies |
| Login → dashboard → login | Cookies, sessions and login plugins | Authentication flow |
| Only an old browser loops | Cached redirects and site data | Repair server rules, then clear affected data |
Server: cloudflare indicates that a response passed through Cloudflare, not that Cloudflare generated the redirect. Origin responses can be forwarded by the CDN. Record the complete failing path, time and each hop, then compare origin logs.
With Flexible, the browser may use HTTPS to Cloudflare while Cloudflare connects to the origin using HTTP. If the origin redirects that request to HTTPS, Cloudflare still uses HTTP for the next origin request, producing the loop. Cloudflare's troubleshooting guide documents this combination.
Check the domain's SSL/TLS mode and port-80 redirects. For a site handling login or submitted data, first install a valid origin certificate, configure the correct domain and enable port 443, then use Full (strict) to encrypt and verify both legs. Switching before origin HTTPS works can replace the loop with a handshake or certificate failure; see 525 and 526 troubleshooting.
An origin redirecting HTTPS back to HTTP can also conflict with an edge HTTPS redirect under Full (strict). Check the direction at both ends instead of repeatedly switching modes. Cloudflare Tunnel has a separate local-service connection model; do not apply ordinary proxied-origin assumptions without checking it.
Read the configuration actually loaded:
sudo nginx -t
sudo nginx -T 2>&1 | less
Inspect the relevant server_name, return 301, return 302, rewrite and proxy_set_header. nginx -T can contain private addresses or credentials; redact before sharing.
If the CDN redirects www to the apex but Nginx redirects the apex to www, both rules can be syntactically valid while looping together. Choose one final address, such as https://example.com, and align CDN, Nginx and the application. Change one location at a time and retain the old settings for rollback.
If this Nginx terminates external HTTPS and the backend listens on local HTTP, check these headers inside the proxy location of the existing HTTPS server:
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
This assumes a backend on port 3000 and valid outer TLS settings. Nginx's reference explains proxy_set_header. The application must also trust the appropriate proxy before using forwarded headers to determine the external scheme.
If HTTPS terminates at an earlier load balancer, this Nginx receives HTTP, so $scheme is http. Copying the fragment can overwrite the original HTTPS information. Have the trusted ingress replace client-supplied headers and pass the scheme according to the actual chain. Do not blindly trust public X-Forwarded-Proto; restrict backend access to the expected proxies.
After edits, run sudo nginx -t, then sudo systemctl reload nginx only on success. Syntax validation does not validate redirect logic; rerun the chain.
After migration or a domain change, public address, installation address and HTTPS detection may disagree. Back up the database and wp-config.php. With WP-CLI, read settings from the site directory as its runtime user:
wp option get home
wp option get siteurl
Compare scheme, hostname and path with the intended setup. In a subdirectory installation, the two paths can legitimately differ. Do not force them to match solely to eliminate a difference. Check whether wp-config.php defines WP_HOME or WP_SITEURL, since constants can override dashboard options. Multisite needs its network-specific checks.
WordPress's HTTPS documentation explains that WordPress must detect the original HTTPS scheme behind a terminating proxy. Otherwise forced HTTPS for administration can loop. Configure detection for your topology before WordPress settings are loaded, with forwarded headers accepted only from trusted ingress.
For a login-only loop, reproduce in a private window and inspect cookie domain, Secure attribute, site address and session storage. Start with recently changed SSL, cache, redirect or login plugins; disable one at a time and record the effect. See the migration and rollback checklist.
If you know the origin IP and your current source is allowed, preserve the hostname and TLS SNI while contacting it directly. Replace this documentation address with the real origin:
curl --resolve example.com:443:203.0.113.10 -sS -D - -o /dev/null https://example.com/
Do not initially add -L; examine the origin's first hop before following another hostname. Success with -k does not prove certificate validity. A Cloudflare Origin CA certificate is not trusted by ordinary curl by default. Direct testing uses a different trust path from browser → Cloudflare; use the appropriate CA or an authorized diagnostic location.
If the origin's first hop is correct and only the CDN path loops, inspect edge redirects and origin mode. If the origin also loops, inspect Nginx and the application. An origin intentionally accepting only Cloudflare can reject direct tests without being faulty; you do not need to open it to all public sources.
- HTTP, HTTPS, www and apex entry points reach the intended address without looping.
- The final response has the expected status. Protected pages may redirect to login, but return correctly after authentication.
- Test the home page, dashboard, callback and a deep path; retain intended paths and query parameters.
- Once a clean private window works, clear only affected browser data and any specific server/CDN cache entries needed.
- Every layer agrees on hostname and scheme. Retain rollback settings and confirm that no certificate failure replaced the loop.
Clearing cookies can reveal an old-session problem, but it does not fix conflicting server rules. Find two repeating Location responses, identify their layers, change one rule and test again.