Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

How to fix “upstream sent too big header while reading response header from upstream” – NGINX

We were setting up a new server with NGINX in reverse proxy when we got the dreaded 502 | Bad Gateway error.

nginx bad gateway

Checking the NGINX error log gave us the following error:

upstream sent too big header while reading response header from upstream

This occurs when NGINX receives a header from the upstream server that is larger than it is configured to handle. This is fairly simple to fix, though you may need to play around with the settings to see which suits you best.

For us, we added the following 3 lines to our NGINX vhost file for the website inside the location block under the server block

 proxy_busy_buffers_size   512k;
 proxy_buffers   4 512k;
 proxy_buffer_size   256k;

Next, restart NGINX.

sudo service nginx restart

That’s it, you’re done