What the message looks like
2026/10/23 08:47:55 [error] 1234#1234: *7890 upstream sent too big header while reading response header from upstream, client: 198.51.100.7, server: cloud.beispiel.de, request: "GET /apps/user_saml/saml/acs HTTP/2.0"Common causes
- Large or many
Set-Cookieheaders, typical after SSO logins (SAML, OIDC) with long tokens. - Long
Content-Security-PolicyorLinkheaders. - Default 4 KB / 8 KB buffers (
fastcgi_buffer_size,proxy_buffer_size) are too small. - Application debug output ends up in headers.
Check
- Find the error in the nginx log
grep 'too big header' /var/log/nginx/error.log | tail -n 5 - Measure the response header size
curl -s -o /dev/null -w '%{size_header}\n' https://cloud.example.com/ - Look at the full headers
curl -sI https://cloud.example.com/login - Show current buffer settings
nginx -T 2>/dev/null | grep -E 'fastcgi_buffer|proxy_buffer'
Fix
- For PHP-FPM:
fastcgi_buffer_size 32k;andfastcgi_buffers 16 16k;in the matchinglocationblock. - For a reverse proxy:
proxy_buffer_size 16k;,proxy_buffers 8 16k;,proxy_busy_buffers_size 32k;. - Apply with
nginx -t && systemctl reload nginx. - Reduce unnecessary or duplicate cookies in the application.
Typical scenario
After connecting the application to an SSO provider, some users get '502 Bad Gateway' right after logging in while others do not. The nginx error log says 'upstream sent too big header while reading response header from upstream'. First use curl -sI straight against the backend to see how many Set-Cookie lines the response has and how large the headers are in total. A value close to 4 KB or 8 KB explains the error.
FAQ
Why does it only happen after the SSO login?
On the redirect back from the identity provider the application sets several session and SAML cookies at once. That one response overflows the buffer.
Can I make the buffers as large as I want?
The values apply per connection. 32–64 KB is harmless; much more points to a problem in the application.
How does this differ from 'Request Header Or Cookie Too Large'?
Here the backend's response is too large for the buffer, so the failure occurs on the way back to the browser and ends as a 502. With the 400 error it is the browser's request including cookies that is too large. They are different buffers with different directives.
Why does it only affect some users?
The headers grow with the session content. Users with many roles, groups or cookies cross the limit first, while lean sessions keep working.
Does a bigger buffer cost a lot of memory?
Buffers are allocated per connection as needed, and a value like 16k or 32k is unproblematic for most setups. It is wiser to remove redundant cookies and oversized claims than to keep raising the limit.