Hi,
My WordPress website is hosted on a VPS server using Nginx, but it is not loading properly. Sometimes it shows a 502 Bad Gateway error, and sometimes the page keeps loading without showing anything.
Server Details:
What I tried:
Still the issue is not fixed.
Can anyone help me:
Thanks
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
When you get a 502 Bad Gateway error, the problem is usually not Nginx itself. Most of the time, Nginx is working, but it cannot get a valid response from the backend service it depends on, which is usually PHP-FPM for WordPress.
For a WordPress site on Nginx + Ubuntu 22.04, the most common causes are:
To troubleshoot it, first check the Nginx error log:
sudo tail -f /var/log/nginx/error.log
Or review recent lines with:
sudo tail -n 50 /var/log/nginx/error.log
That log usually tells you whether Nginx failed to connect to PHP-FPM, hit a timeout, or found a bad upstream definition.
Since WordPress runs through PHP, the next important step is to check PHP-FPM logs and status.
First, see which PHP version is installed:
php -v
Then check the PHP-FPM service:
sudo systemctl status php8.1-fpm
On Ubuntu 22.04, the PHP-FPM log is often here:
sudo tail -n 50 /var/log/php8.1-fpm.log
You can also inspect the system journal:
sudo journalctl -u php8.1-fpm -n 50 --no-pager
If PHP-FPM is stopped or failing, restart it:
sudo systemctl restart php8.1-fpm
Also confirm that Nginx is pointing to the correct PHP socket. In your Nginx site config, look for something like:
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
If Nginx points to the wrong PHP version or a missing socket, you can get intermittent 502 errors immediately.
After that, check WordPress/application-level logs. For WordPress, enable debugging in wp-config.php:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Then review:
tail -n 50 /path/to/wordpress/wp-content/debug.log
That helps catch plugin, theme, and PHP fatal errors that do not always appear clearly in the browser.
It is also worth checking whether the server is running out of memory:
free -h
dmesg -T | grep -i -E 'killed process|out of memory'
If PHP-FPM workers are being killed by the OOM killer, the site may alternate between hanging and returning 502.
A practical fix checklist would be:
nginx/error.logphp-fpm service status and logsfastcgi_pass socket/path in Nginxsudo nginx -t
sudo systemctl reload nginx
sudo systemctl restart php8.1-fpm
Heya, @511c1785d2404350b53231089c0190
This usually isn’t a WordPress issue itself — a 502 on Nginx almost always means it can’t talk to PHP-FPM (or whatever backend is handling PHP).
Since you’re seeing both 502 and hanging requests, I’d start there.
First, check the Nginx logs. That will usually tell you pretty quickly what’s going wrong:
sudo tail -f /var/log/nginx/error.log
If it’s a 502, you’ll often see something like “connection refused” or “upstream timed out”, which points to PHP-FPM.
Then check if PHP-FPM is actually running:
sudo systemctl status php*-fpm
If it’s stopped or failing, restart it:
sudo systemctl restart php*-fpm
Also make sure your Nginx config is pointing to the correct socket or port. A very common issue is a mismatch like:
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
but the actual version running is different (e.g. php8.2), so the socket path doesn’t exist.
If the service is running but you still get timeouts, it could be:
PHP-FPM overloaded (too many requests)
low memory on the VPS
long-running WordPress plugins
You can check PHP-FPM logs as well:
sudo tail -f /var/log/php*-fpm.log
So yeah, I’d focus on:
Nginx error log
PHP-FPM status
matching the correct socket/version
That usually narrows it down pretty quickly.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.