Root Causes & Failure Triggers
An Nginx 504 Gateway Timeout error indicates that the Nginx reverse proxy timed out waiting for a response from an upstream server or PHP worker.
- Long-running PHP/backend script exceeding Nginx's default 60-second read timeout.
- Deadlocked or unindexed slow database queries halting execution.
- PHP-FPM request_terminate_timeout triggering a premature abort.
- Hanging third-party external API requests blocking the execution thread.
Step-by-Step Fixes
1. Increase Nginx Upstream Read Timeouts
Add timeout directives inside your Nginx server or location block: fastcgi_read_timeout 300; proxy_read_timeout 300; proxy_connect_timeout 300;
2. Raise PHP Execution Limits in php.ini
Update execution time in your php.ini: max_execution_time = 300
3. Adjust PHP-FPM Worker Pool Timeout
In /etc/php/8.3/fpm/pool.d/www.conf configure: request_terminate_timeout = 300s
4. Reload Nginx and PHP-FPM Daemons
Verify configuration syntax and restart: sudo nginx -t && sudo systemctl reload nginx && sudo systemctl restart php8.3-fpm
💡 Live Diagnostics: Verify your server's SSL chain, DNS records, and HTTP headers using our SSL Checker, Security Headers, or Open Port Scanner tools.
Related Error Troubleshooting Guides
How to Fix Laravel 419 Page Expired (CSRF Token Mismatch)Fix Nginx 502 Bad Gateway Error with PHP-FPM / UpstreamHow to Fix CORS Error: No 'Access-Control-Allow-Origin' HeaderHow to Fix WordPress 500 Internal Server Error (.htaccess & Memory)How to Fix ERR_SSL_PROTOCOL_ERROR in Chrome & BrowsersFix ERR_TOO_MANY_REDIRECTS (Redirect Loop 310) in WordPress & CloudflareFix WordPress 'Error Establishing a Database Connection' ErrorHow to Fix SSH Connection Refused (Port 22) on Ubuntu/Linux