Fix 502 Bad Gateway error on WordPress can be complicated if you don’t have proper tools

WARNING. The steps below should be performed by experienced people as they are potentially dangerous and could damage the server. If you don’t know what you are doing you can request a free quote

What is 502 Bad Gateway error

The 502 Bad Gateway error typically occurs when a server acts as a gateway and fails to communicate with another destination server to fulfill the client’s request.

It can often happen, for example, if you use Cloudflare, which acts as a proxy, to increase the security and performance of Web sites.

upstream sent too big header while reading response

Going to check the server log where the error occurred, often the words upstream sent too big header while reading response header from upstream appear. Such wording indicates that the header sent is too large to be read by our server.

Solve 502 Bad Gateway error from Plesk

To resolve the error through Plesk, simply proceed with the following steps:

  1. Access the Apache & nginx settings of the domain
  2. In the Additional Nginx Directives section, add the following commands:
    proxy_buffering  on;
    proxy_buffers 4 256k;
    proxy_buffer_size 128k;
    proxy_busy_buffers_size 256k;
  3. Save the settings you just entered

Once these steps are completed, the error should be gone.

Fix 502 Bad Gateway error from terminal

If, instead, you want to resolve the 502 Bad Gateway from the terminal or, for example, you want to make sure that you resolve on all server domains without having to repeat it among the settings of each, after logging in to the console as administrator:

  1. Verify that within the /etc/nginx/conf.d/ folder the directives.conf file exists.
  2. If the file does not exist create it with
    touch /etc/nginx/conf.d/directives.conf
  3. Open and edit file
    nano /etc/nginx/conf.d/directives.conf
  4. Add the following directives and save
    proxy_buffering  on;
    proxy_buffers 4 256k;
    proxy_buffer_size 128k;
    proxy_busy_buffers_size 256k;
  5. Make sure the new guidelines are correct
    nginx -t

    the positive answer should be

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
  6. Restart Nginx services
    service nginx reload

Source:

Fix 502 Bad Gateway error Quote

    Contact us for a free quote