Report this

What is the reason for this report?

How to fix website not loading issue on VPS server (Nginx + WordPress)

Posted on April 7, 2026

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:

  • VPS (Ubuntu 22.04)
  • Nginx server
  • WordPress installed

What I tried:

  • Restarted Nginx and MySQL
  • Checked server status
  • Cleared cache

Still the issue is not fixed.

Can anyone help me:

  1. What is causing this issue?
  2. How to check Nginx error logs?
  3. How to fix 502 error on VPS?

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!

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.

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:

  • PHP-FPM is down or stuck
  • Wrong PHP-FPM socket/path in the Nginx config
  • PHP worker exhaustion from heavy traffic, bad plugins, or slow requests
  • Timeouts caused by a slow plugin, theme, or external API call
  • Low server memory, causing PHP-FPM or MySQL to crash
  • Less commonly, database issues can make WordPress hang, even if they do not directly trigger every 502

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:

  1. Check nginx/error.log
  2. Check php-fpm service status and logs
  3. Verify the fastcgi_pass socket/path in Nginx
  4. Enable WordPress debug logging
  5. Check memory usage and OOM events
  6. Temporarily disable heavy or recently added plugins
  7. Reload services after changes:
sudo 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:

  1. Nginx error log

  2. PHP-FPM status

  3. matching the correct socket/version

That usually narrows it down pretty quickly.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.