Introduction An HTTP to HTTPS redirect loop causes browsers to show "ERR_TOO_MANY_REDIRECTS" errors. This happens when the redirect logic is misconfigured, often involving the X-Forwarded-Proto header.

Symptoms - Browser: "ERR_TOO_MANY_REDIRECTS" - curl shows multiple 301 redirects - Redirect loop for all URLs or specific paths - Works without load balancer but fails with it - Some browsers affected more than others

Common Causes - Load balancer terminating SSL but backend also redirecting - X-Forwarded-Proto not being checked before redirect - Redirect rule on both load balancer and backend - Backend detecting HTTP because SSL terminated at LB - Mixed redirect rules (301 vs 302)

Step-by-Step Fix 1. **Check redirect configuration at each layer': ```bash # Check load balancer redirect curl -vI http://example.com/ # Check backend redirect (bypass LB) curl -vI http://backend-ip/ ```

  1. 1.**Fix backend to check X-Forwarded-Proto':
  2. 2.```nginx
  3. 3.# Nginx backend
  4. 4.if ($http_x_forwarded_proto = 'http') {
  5. 5.return 301 https://$host$request_uri;
  6. 6.}
  7. 7.`
  8. 8.**Remove duplicate redirect rules':
  9. 9.Ensure redirect is only configured at the load balancer level, not on backends.

Prevention - Configure redirect at only one layer (preferably LB) - Check X-Forwarded-Proto before redirecting - Test redirect behavior after any SSL changes - Monitor redirect loop errors in application logs - Use HSTS headers to prevent HTTP requests