# Incident note: nginx: upstream sent too big header – fix

> Incident note: nginx logs upstream sent too big header and returns 502? The backend headers do not fit the buffer. How to raise the fastcgi and proxy…

Author: Daniele Michelin · Published: 2026-12-06 · Updated: 2026-12-06 · Language: en
Canonical: https://daniele-michelin.com/en/blog/incident-note-nginx-too-big-header/

The backend's response headers (usually cookies) are larger than the buffer nginx reserves for them; nginx gives up and returns 502 Bad Gateway.

## Read the signal

Start with the exact wording of the error and its timestamp in the log. Then narrow down the cause before changing anything.

```
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"
```

## Narrow down possible causes

- Large or many `Set-Cookie` headers, typical after SSO logins (SAML, OIDC) with long tokens.
- Long `Content-Security-Policy` or `Link` headers.
- Default 4 KB / 8 KB buffers (`fastcgi_buffer_size`, `proxy_buffer_size`) are too small.
- Application debug output ends up in headers.

## Check before changing anything

- 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 and test again

- For PHP-FPM: `fastcgi_buffer_size 32k;` and `fastcgi_buffers 16 16k;` in the matching `location` block.
- 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.
Then repeat the original action and compare the result with the initial error.

## Keep a note for the next ticket

Record the exact error, the check result, the change and the retest. That gives the team a useful starting point next time.

## 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.

[Full error guide: nginx: upstream sent too big header while reading response header](https://daniele-michelin.com/en/errors/nginx-upstream-sent-too-big-header/)
