# HTTP→HTTPS redirect loop behind a load balancer or reverse proxy (X-Forwarded-Proto)

**Code:** `Redirect loop` · **Category:** HTTP · **Seen on:** HTTP, Nginx, AWS, Laravel

The app forces HTTPS, but TLS ends at the proxy, so the app always sees HTTP and keeps redirecting.

## Meaning

The proxy talks plain HTTP to the app and the app redirects every request to https:// forever (ERR_TOO_MANY_REDIRECTS). Make the app trust `X-Forwarded-Proto` (`TRUSTED_PROXIES`, `app.set("trust proxy")`, `SECURE_PROXY_SSL_HEADER`) and ensure the proxy sets it.

## Common causes

- App doesn't trust `X-Forwarded-Proto`
- Proxy not setting the header
- Cloudflare Flexible SSL with an HTTPS-only origin
- `force_ssl` / `$_SERVER['HTTPS']` check
- Redirect rule in both proxy and app

## Quick fix

1. Trust the proxy header in the framework
2. `proxy_set_header X-Forwarded-Proto $scheme;`
3. Use Full (strict) SSL mode at the CDN

## Detailed fix by platform

### Express

1. `app.set("trust proxy", 1);   // so req.protocol uses X-Forwarded-Proto`

## How to diagnose

1. **Header** — Sent by proxy?
2. **App** — Trusts it?
3. **SSL mode** — Full?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/http/redirect-loop-x-forwarded-proto)
