Skip To Main Content | Accessibility

Begin Main Content
Index
No registered users in community xowiki
in last 10 minutes

Nginx Proxy: upstream sent too big header while reading response header from upstream

If you're running an Nginx proxy configuration, you can run into the following error in your logs.

$ tail -f error.log
[error] 19896#0: upstream sent too big header while reading response header from upstream,
client: 10.5.120.6,
server: host.tld,
request: "GET /path/to/file.php HTTP/1.1",
upstream: "",
host: "host.tld"

[error] 19899#0: upstream sent too big header while reading response header from upstream,
client: 10.5.120.6,
server: host.tld,
request: "GET /path/to/file.php HTTP/1.1",
upstream: "",
host: "host.tld"

In your Nginx proxy configuration, you probably have something very similar to this:

server {
listen 80;
server_name host.tld;

location / {
proxy_pass http://upstream;
...
}
}

To resolve this issue, increase the proxy buffers that nginx uses. Before nginx sends a response back to your visitor, it will cache the request it had to make from its upstream. However, there are limited buffers available to buffer such a response. If the HTTP headers contain more info than anticipated, those proxy buffers can get saturated and nginx will drop the request with the "upstream sent too big header while reading response header from upstream" error in your logs.

To resolve it, add the proxy_buffer_size configurations to your location block.

server {
listen 80;
server_name host.tld;

location / {
proxy_pass http://upstream;
...

proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
}

That change increases Nginx's proxy buffer from the default 4KB to 128KB, usually big enough to cache any backend response without posing a risk to your server. After all, that server now has to assign more memory to buffer each backend response.