How to Fix 504 Gateway Timeout using Nginx

December 19, 2021

Common Error Messages

  • "504 Gateway Timeout"
  • "504 Gateway Time-Out"
  • "504 Gateway Timeout NGINX"
  • "Nginx 504 Gateway Timeout"
  • "HTTP 504 Gateway Timeout"
  • "HTTP 504 Error"
  • "HTTP 504"
  • "Gateway Timeout (504)"

Fix for Nginx + FastCGI (php-fpm)

1. Update PHP Configuration

Modify php.ini file (/etc/php.ini):

max_execution_time = 300

2. Update PHP-FPM Configuration

Edit /etc/php-fpm.d/www.conf:

request_terminate_timeout = 300

3. Update Nginx Virtual Host

location ~ .php$ {
    root /var/www/sites/nginxtips.com;
    try_files $uri =404;
    fastcgi_pass unix:/tmp/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_read_timeout 300;
}

Fix for Nginx as Proxy

Add to nginx.conf:

proxy_connect_timeout       600;
proxy_send_timeout          600;
proxy_read_timeout          600;
send_timeout                600;

Reload Configuration

service nginx reload
#Nginx #Server #Timeout #PHP-FPM