Fix 502 Bad Gateway error on WordPress can be complicated if you don’t have proper tools
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:
- Access the Apache & nginx settings of the domain
- 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;
- 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:
- Verify that within the /etc/nginx/conf.d/ folder the directives.conf file exists.
- If the file does not exist create it with
touch /etc/nginx/conf.d/directives.conf
- Open and edit file
nano /etc/nginx/conf.d/directives.conf
- Add the following directives and save
proxy_buffering on; proxy_buffers 4 256k; proxy_buffer_size 128k; proxy_busy_buffers_size 256k;
- 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
- Restart Nginx services
service nginx reload
Source:
- https://stackoverflow.com/questions/57294212/502-bad-gateway-error-upstream-sent-too-big-header-while-reading-response-head
- https://www.plesk.com/kb/support/how-to-add-additional-nginx-directives-globally-on-a-plesk-server/