Troubleshooting guide

NGINX 502 Bad Gateway with PHP-FPM: Production Troubleshooting Guide

Find common causes of NGINX 502 Bad Gateway errors with PHP-FPM, including socket paths, service failures, permissions, timeouts and high load.

Remote support availableCommercial systemsService: NGINX Support
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 service. 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 service is stopped or repeatedly restarting
  • Site fails under traffic but works after restart
  • WordPress admin or checkout fails intermittently

Common causes

  • PHP-FPM service 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 help identify the direction of the issue. Always adjust paths, service 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 monitoring for PHP-FPM worker saturation

When to get help

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

Need this fixed?

Get remote support for this issue.

Fixed technical support starts from $499. Emergency incident support is $199/hr with a minimum window.

Contact Us

Related guides