Skip to content

nginx error: 'upstream sent too big header'

Some pages on your site return a 502 to visitors while others load fine. In the nginx error log you see:

upstream sent too big header while reading response header from upstream

This article explains what it means and how to fix it.


What's happening

nginx buffers response headers coming back from PHP-FPM before it forwards them to the visitor. That buffer has a fixed size. When PHP-FPM sends more header data than fits, nginx drops the response and returns a 502. The log line above is what nginx writes in that case.

The error often shows up only for some requests. That's because response header size depends on what the response contains — a page can be fine for a logged-out visitor and break the moment you log in as admin, when the CMS adds extra session cookies and toolbar headers.

Fix

Add larger FastCGI buffer values to the virtual host's 'Custom Config' field:

fastcgi_buffer_size 32k;
fastcgi_buffers 16 16k;
  • fastcgi_buffer_size is the buffer used for response headers — the one this error is about. The default is 4k or 8k depending on the platform.
  • fastcgi_buffers sets the number and size of buffers used for the response body. It's usually raised alongside fastcgi_buffer_size.

There's no formula for the right size. Doubling or quadrupling the defaults is the common starting point — pick a value that fits your worst-case headers with room to spare. If 502s continue, raise them further.

For where to find the 'Custom Config' field and how to edit it, see All about virtual hosts.