nginx returns 502 for login requests only, with `upstream sent too big header while reading response header from upstream`.
IntermediateTroubleshootingLoad balancers and reverse proxies
Answer
Likely causes → The upstream's response headers exceed proxy_buffer_size (4 KB or 8 KB by default). Login responses often carry large Set-Cookie headers (JWTs, SSO cookies) that push them over.
Diagnose →
curl -s -o /dev/null -D - http://127.0.0.1:8080/login -d 'u=x&p=y' | wc -c
Fix →
proxy_buffer_size 16k;
proxy_buffers 8 16k;
proxy_busy_buffers_size 32k;
For FastCGI the equivalents are fastcgi_buffer_size / fastcgi_buffers.
Prevent → Keep cookies small (store session data server side, reference by ID) and include auth flows in load tests.
More on Load balancers and reverse proxies
nginx returns `502 Bad Gateway` and the error log says `connect() failed (111: Connection refused) while connecting to upstream`.Beginnernginx returns `504 Gateway Time-out` with `upstream timed out (110: Connection timed out) while reading response header from upstream`.BeginnerAn ALB target group shows all targets `unhealthy` with `Health checks failed with these codes: [404]`.BeginnerAn ALB returns sporadic `502`s, and access logs show `elb_status_code=502` with `target_status_code=-`. Load is low.Intermediatenginx logs `upstream prematurely closed connection while reading response header from upstream`.Intermediatenginx error log shows `no live upstreams while connecting to upstream` and every request gets 502.Intermediate