502 Bad Gateway / upstream sent too big header while reading response header from upstream on hosted NGINX website

On an NGINX hosted website when accessing /wp-admin on your WordPress hosted website, you might encounter the following error:

502 Bad Gateway

500 errors often reveal more information in the NGINX server error log file. When doing the following command:

tail -f /home/domain.com/logs/error_log

You might see the following:

2019/09/25 06:26:21 [error] 19254#19254: *26700 upstream sent too big header while reading response header from upstream, client: x.x.189.140, server: sitename.com, request: "GET /wp-login.php?redirect_to=http%3A%2F%2Fwww.sitename.com%2Fwp-admin%2F&reauth=1 HTTP/1.1", upstream: "fastcgi://unix:/var/php-nginx/15692533519133.sock/socket:", host: "www.sitename.com"

The problem is solved by adding fastcgi_buffers and fastcgi_buffer_size directives in your NGINX configuration file. On a Virtualmin server for example, you might do this:

In /etc/nginx/nginx.conf add

http {

   fastcgi_buffers 16 16k;
   fastcgi_buffer_size 32k;

And then restart NGINX.

If you Google NGINX and upstream sent too big header while reading response header from upstream

you will get a multitude of slightly varying answers. The bottom line is there is a specific way to calculate the buffers size, a rather technical way. In our reference below from the comment of the accepted answer it is said:

“While your answer led me to the correct response, you should show how to determine the correct buffer sizes and why that matters. Otherwise it’s a shot in the dark. See here for getting an idea on sizing…”

So if you’re in a rush to get things working, use the directives as indicated above. Otherwise follow the references below for more information:

References:
https://gist.github.com/magnetikonline/11312172#determine-fastcgi-response-sizes
https://stackoverflow.com/questions/23844761/upstream-sent-too-big-header-while-reading-response-header-from-upstream

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top