Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

oraparicio's avatar

Nginx, PHP7 & Wordpress

Hi everyone, im a total newbie to nginx... (worked with apache like for 15 years) and recently i moved a couple of Wordpress sites to Digital Ocean 2.0 with Forge and everything went ok, until suddenly i started getting 502 Bad Gateway errors... but this is NOT a permanent error, it just happens ramdomly and when it does i just refresh the browser and it loads ok. I did a lot of research on the web and even read the nginx documentation but all the possible solutions are for a permanent and constant 502 error, in my case everything is as far i could check very well configured (i'm using the 'out of the box' forge configuration for the nginx and php-fpm files). I don't know what else to do!!!, i even think of getting back to apache but i assume that this MUST be just a configuration or tweaking issue. My wordpress blog have a medium-low traffic and my digital ocean server is a 2GB ram/ 40GB SSD/ 3TB BW stack so it can't be a server resource issue... in fact this blog worked perfectly fine in a lower resource server with apache... Help please!!! greeting from Lima, Peru!

0 likes
1 reply
fideloper's avatar

Bad Gateway means that php-fpm is returning an error to Nginx, so the trick is discovering what's going on in php-fpm. There might be more info in /var/log/php5-fpm.log (not 100% sure I have that filename right, it'll be close to that).

This might just be disguising an error that was always there, but resurfacing in a different way. Getting errors from Wordpress is a bit tricky since I don't believe it has a mechanism for capturing errors - so I'd check to ensure that php-fpm is setup to log a log file somewhere, and perhaps check php.ini directives to enable error reporting, increase memory limits, and perhaps check for it's own PHP log.

They key will be to discover, somewhere, somehow, an error message!

Bad Gateway may also occur if Nginx can't communicate to PHP, so double check to make sure there isn't an overflow of traffic to your server that you don't expect - something overloading the server?

Perhaps add the free tier of New Relic server monitoring to see if it spots any issues (full disk?)

Please or to participate in this conversation.