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

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, March 11, 2016

Follow me on Twitter as @mattiasgeniar

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, we need to increase the proxy buffers that nginx uses.

Before nginx sends a response back to your visitor, it will buffer 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.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.