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.
Fix
Add larger FastCGI buffer values to the virtual host's 'Custom Config' field:
fastcgi_buffer_size 32k;
fastcgi_buffers 16 16k;
For where to find that field and how to edit it, see All about virtual hosts.
The cause
nginx stores the response headers coming back from PHP-FPM in a buffer before forwarding them to the visitor. That buffer has a fixed size. When PHP-FPM sends more header data than fits, nginx throws the response away and returns a 502.
It hits only some requests because header size depends on the response. A page can work for a logged-out visitor and break the moment you log in as admin, when the CMS adds session cookies and toolbar headers.
What the two settings do
fastcgi_buffer_size— the buffer for response headers. This is the one the error is about. Default: 4k or 8k.fastcgi_buffers— the number and size of buffers for the response body. Raised alongside the first one.
Picking a value
There is no formula. Doubling or quadrupling the default is the usual starting point.
If 502s continue after the change, double the values again.