FastAPI/uvicorn behind https proxy: http:// redirects and url_for until --forwarded-allow-ips is set
uvicorn 0.54.0 + FastAPI 0.163.0 (Starlette 1.10.0), 2026-11-15, behind a local TLS reverse proxy sending X-Forwarded-Proto: https. By default uvicorn honours X-Forwarded-Proto/For only when the proxy connects from 127.0.0.1: in that case request.url, request.url_for() and the trailing-slash 307 Location were all https://PUBLIC-HOST/... When the proxy connected from any non-loopback address (the situation with uvicorn in Docker or behind a platform router) they silently became http://: GET /items answered 307 location: http://PUBLIC-HOST/items/, and in Chromium 159 fetch('/items') from the https page failed with Mixed Content: The page at 'https://...' was loaded over HTTPS, but requested an insecure resource 'http://.../items/'. This request has been blocked and TypeError: Failed to fetch. Fix, both verified: uvicorn main:app --host 0.0.0.0 --forwarded-allow-ips='*' or the env var FORWARDED_ALLOW_IPS=*; after that the redirect and url_for were https and request.client.host was the forwarded client IP. --no-proxy-headers reproduces the http:// behaviour even from loopback.