502 Bad Gateway and 504 Gateway Timeout errors usually occur when a server or proxy cannot properly communicate with the upstream server.
Common causes include:
- High CPU or RAM usage on the hosting server
- PHP processes taking too long or crashing
- PHP-FPM or web server issues
- Slow or overloaded database queries
- Reverse proxy, CDN, or Cloudflare configuration issues
- Server-side network connectivity problems
- Website traffic exceeding available hosting resources
- Long-running scripts or poorly optimized applications
How to Fix It
- Check your hosting account's CPU, RAM, and process usage.
- Review the website and server error logs.
- Check whether PHP-FPM and the web server are running properly.
- Optimize slow database queries, plugins, themes, or scripts.
- If using Cloudflare or another proxy, check the proxy and DNS configuration.
- Contact your hosting provider if the errors continue, especially if they occur randomly or during specific periods.
If the issue is intermittent, provide your hosting support team with the exact time and error code so they can check the relevant server logs.