Differences

This shows you the differences between two versions of the page.

Link to this comparison view

504_gateway_time-out_using_nginx_en [2017/09/05 12:18] (current)
Line 1: Line 1:
 +====== 504 Gateway Time-out using Nginx ======
  
 +It is very common to see a **504 Gateway Time-out using Nginx** webserver. This timeout error is generated often by a number of reasons on the backend connection that is serving content. To fix it, you will have to figure out what configuration are you using.
 +
 +For **Nginx + FastCGI (php-fpm)**,​ you should try to tweak nginx configuration in this way-:
 +
 +Try raising max_execution_time setting in php.ini file (**CentOS** path is /​etc/​php.ini) or (**Debian** path is /​etc/​php5/​fpm/​php.ini):​
 +
 +<sxh bash>
 +max_execution_time = 300
 +</​sxh>​
 +
 +But, you should also change set request_terminate_timeout parameter (commented by default) at www.conf file from PHP-FPM (CentOS path is /​etc/​php-fpm.d/​www.conf) or (Debian path is : /​etc/​php5/​fpm/​pool.d/​www.conf)
 +
 +Then set the variable to the same value as max_execution_time:​
 +<sxh bash>
 +request_terminate_timeout = 300
 +</​sxh>​
 +
 +Now let’s add  fastcgi_read_timeout variable inside our Nginx virtual host configuration:​
 +<sxh nginx>
 +      location ~ \.php$ {
 +        include snippets/​fastcgi-php.conf;​
 +        fastcgi_pass unix:/​var/​run/​php5-fpm.sock;​
 +        fastcgi_read_timeout 300;
 +     }
 +</​sxh>​
 +
 +In another cases we have the control of the timeout into the Nginx Server configuration like this into nginx.conf
 +<sxh nginx>
 +        ## Timeouts ##
 +        # Timeout for reading of the client body
 +        client_body_timeout ​  300;
 +        # Timeout for reading the client header
 +        client_header_timeout 300;
 +        # Timeout for keep-alive ​
 +        keepalive_timeout ​    300;
 +        # Timeout for response request ​
 +        send_timeout ​         300;
 +        ## Timeouts ##
 +</​sxh>​
 +
 +Then restart nginx:
 +<sxh bash>
 +service nginx reload
 +</​sxh>​
 +
 +For **Nginx as Proxy** for Apache web server, this is what you have to try:
 +
 +Add this variables to nginx.conf file:
 +<sxh nginx>
 +proxy_connect_timeout ​      600;
 +proxy_send_timeout ​         600;
 +proxy_read_timeout ​         600;
 +send_timeout ​               600;
 +</​sxh>​
 +  ​
 +Then restart nginx:
 +<sxh bash>
 +service nginx reload
 +</​sxh>​
 +
 +====== References ======
 +  - https://​www.scalescale.com/​tips/​nginx/​504-gateway-time-out-using-nginx/​