Fixing bad gateway issue 502

Posted July 4, 2017 5.4k views
UbuntuServer Optimization

Hi everyone,

From time to time my website is getting error 502 bad gateway or just simply doesent loading up. When I’m looking at the graphs of CPU usage I’ve realized that when I want to edit some posts on wordpress the CPU usage increasing to high levels like 90%.

What I’m supposed to do, restart the droplet or resize the plan? When I do this everything will be good?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Hi @brzezickiandrzej

What web server are you using, Apache or Nginx? Which version?
And which version of PHP?
Are you running Ubuntu 14.04 or a different version?

When you have the problem with high CPU, which process is eating everything?
You can run the command top to see processes and amount of CPU+RAM they eat.

Usually the problem is rooted in a bad plugin in WordPress, since the way it’s crashing.
How big is your droplet?

I’m using Nginx, Ubuntu 14.04.

How I am supposed to check which plugin is causing the problem?
Screenshot of console

  • @brzezickiandrzej

    Are you only running WordPress on the server?

    I would recommend that you move away from HHVM, since PHP 7 has become even faster.
    And since you’re running a fairly old version of everything, I would guess HHVM is also old, which means it’s not very stable - and might actually be the reason for the crashes (well, it’s guaranteed HHVM that is crashing, but the reason behind is unknown).

    When it crashes, then please include the last 30 lines from the error log - run this:

    tail -30 /var/log/nginx/error.log

    Edit: The screenshot didn’t show high CPU - actually about 99% idle.