nginx returns 502 for some users only, with "upstream sent too big header while reading response header from upstream".
IntermediateTroubleshooting5xx errors
Answer
Likely causes → The backend's response headers exceed nginx's proxy buffer, usually a large Set-Cookie (session data stored in the cookie) or a big auth header. Only users with large sessions hit it.
Diagnose →
grep 'too big header' /var/log/nginx/error.log | tail
curl -s -D - -o /dev/null https://app.example.com/dashboard -H "Cookie: $USER_COOKIE" | wc -c
Fix →
proxy_buffer_size 16k;
proxy_buffers 8 16k;
On ingress-nginx, set nginx.ingress.kubernetes.io/proxy-buffer-size: "16k".
Prevent → Keep sessions server-side and cookies small.
More on 5xx errors
Right after a release, 500s spike to 8% and logs show `java.lang.NullPointerException` in a new code path.BeginnerLong-running report exports fail with "504 Gateway Time-out" from the ALB at exactly 60 seconds.Beginnernginx logs "upstream prematurely closed connection while reading response header from upstream" and users get 502.IntermediateEvery deploy causes 10–20 seconds of 502s from the ALB, even with a rolling update.IntermediateA Node.js service behind an ALB returns a steady trickle of 502s under normal load, with no app errors at all.AdvancedThrough Istio, clients get "503 upstream connect error or disconnect/reset before headers. reset reason: connection failure".Intermediate