502 Bad Gateway Error: What is this error and how do you fix it?


+2 votes
Good day to you!

On my website I sometimes see “502 Bad Gateway” error. Could you, please, tell me what it means and what actions I should take to fix it?

Thank you in advance!
asked Oct 19, 2016 in System administration by Eric

1 Answer

0 votes

Good day!
In 99% of cases, 502 Bad Gateway error indicates that there are problems on the server side, on which the website operates. 
502 Bad Gateway - is an HTTP protocol error, which is returned by the front-end server when it cannot receive the content from the backend servers.

502 Bad Gateway error

What a user can do when facing 502 Bad Gateway error:

  1. If possible, inform the administration about the error. It can be done, using Twitter, social networks or via e-mail.
  2. Open the website later. All good internet projects have administrators on duty in their stuff, who is responsible for tracking this error and return the site to the working condition as soon as possible. 
  3. If the site doesn’t work for a long time, try finding the necessary information on another site.

What a site administrator can do when facing 502 Bad Gateway error:

In most cases, a 502 Bad Gateway error is returned to a user by nginx. It means that you use nginx as a front-end server and PHP-fpm or apache as a backend server. Your backend server failed to function and you need to restore its operability. Below there is a recommended sequence of operations for prompt service recovery:

  1. Reload your Apache or PHP-fpm server (restart the service). The service may have hung up due to heavy traffic, for instance.
  2. Check operability of backend services, such as MySQL and Memcached. It happens rarely, but they also may become the reason for 502 Bad Gateway error.
  3. If one of the services won’t start - use DF –h command to check free space on the server disk, if there is no free space – immediately clear it and restart the services.
  4. Use “top” command to check the server load; if it’s too high (la indicator exceeds 10) – reload the server completely, using reboot command.

If you have any questions left or need some - please, ask a question or leave a comment. 
I’m always pleased to help you!

answered Oct 19, 2016 by Expert Brian (5,370 points)
Welcome to Help Desk, here you can ask any questions and receive answers from our experts and other members of the community.

If you have any questions, please do not hesitate to contact our help desk!

Make a question!