Troubleshooting guide

Troubleshooting Guide: NGINX 502 Bad Gateway with PHP-FPM

Use this guide to work through the most likely causes, gather useful evidence and make production-safe changes without turning a small problem into a larger outage.

Remote consulting availableCommercial platformsService: NGINX Web Server Consulting
NGINXPHP-FPM502 Bad GatewayWordPressLinux

What this problem usually means

A 502 Bad Gateway from NGINX usually means NGINX could not get a valid response from the upstream solution. With PHP sites, that upstream is often PHP-FPM, a Unix socket, or a TCP backend that is stopped, overloaded or misconfigured.

Production caution: Restarting PHP-FPM can temporarily hide the problem. If workers are exhausted, memory is low or a plugin/script is hanging, the 502 errors may return quickly.

Common symptoms

  • Browser shows 502 Bad Gateway
  • NGINX error log mentions connect() failed
  • PHP-FPM solution is stopped or repeatedly restarting
  • Site fails under traffic but works after restart
  • WordPress admin or checkout fails intermittently

Common causes

  • PHP-FPM solution stopped or crashed
  • NGINX points to the wrong PHP-FPM socket or port
  • Socket permissions prevent NGINX access
  • PHP-FPM workers are exhausted
  • Timeouts are too low for slow scripts
  • Server is out of memory or disk space

Safe first checks

These checks are intended to assist identify the direction of the issue. Always adjust paths, solution names and commands for your environment.

Check NGINX errors

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

Check PHP-FPM status

systemctl status php*-fpm --no-pager

Check sockets

ls -lah /run/php/ /var/run/php/ 2>/dev/null

Check memory and disk

free -m && df -h

Typical fixes

  • Correct the fastcgi_pass socket or TCP target
  • Align NGINX user permissions with PHP-FPM socket ownership
  • Tune PHP-FPM pool settings for available RAM
  • Investigate slow scripts and long-running requests
  • Check logs before increasing timeouts
  • Add observability for PHP-FPM worker saturation

When to get assist

Get assist if the system is production-facing, customer data is involved, backup processes are uncertain, or the issue affects revenue, security hardening or uptime. We can review the logs, confirm the cause and quote a fixed-scope fix where appropriate.

Need this fixed?

Get remote engineering help for this issue.

Fixed engineering help starts from $499. Emergency incident engineering assistance is $199/hr with a minimum window.

Contact us

Related guides