nginx 504 error: Gateway Timeout

Refers to:

  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux
  • Plesk 11.0 for Linux
  • Plesk 11.5 for Linux
  • Plesk 12.0 for Linux

Created:

2016-11-16 12:40:16 UTC

Modified:

2017-02-27 11:31:22 UTC

4

Was this article helpful?


Have more questions?

Submit a request

nginx 504 error: Gateway Timeout

Symptoms

Multiple '504 errors' are shown on SSL pages or it takes a lot of time to load the website page. This can be fixed by restarting the 'apache' service, but the problem reoccurs.

Also the issue accrues when any large file (1+ GB) is being uploaded to any php software.

In domain logs /var/www/vhosts/example.com/logs/ the following error can be found:

2013/11/15 03:32:13 [error] 12699#0: *5042589 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 203.0.113.2, server: example.com, request: "GET /wp-login.php HTTP/1.0", upstream: "https://203.0.113.2:7081/wp-login.php", host: "example.com", referrer: "https://example.com/register/"

Cause

Timeout error is often caused by issues on the backend connection that is serving the content. To fix this, first, you have to figure out what configuration you are using.

Resolution

For Nginx as Proxy (php-fpm disabled)

  • To apply settings globally, increase the timeout values by creating the file /etc/nginx/conf.d/timeout.conf and restarting 'nginx' service:

    # cat /etc/nginx/conf.d/timeout.conf

    proxy_connect_timeout       600;
    proxy_send_timeout 600;
    proxy_read_timeout 600;
    send_timeout 600;
  • To increase timeout settings for a particular domain, add the lines mentioned above to 'Additional Nginx directives' at:

    Plesk > Subscriptions > example.com > Websites & Domains > example.com > Apache & nginx Settings


For Nginx + FastCGI (php-fpm enabled)

  • Increase the value of max_execution_time directive (by choosing the value from the drop-down menu or by setting it manually) at:

    Plesk > Subscriptions > example.com > Websites & Domains > example.com > PHP Settings

  • Add fastcgi_read_timeout 300; directive inside the 'nginx' virtual host configuration at:

    Plesk > Subscriptions > example.com > Websites & Domains > example.com > Apache & nginx Settings > Additional Nginx directives

  • Add/increase the following values in the 'http' section in the /etc/nginx/nginx.conf file:

    fastcgi_buffers 8 128k;
    fastcgi_buffer_size 256k;

    Restart 'php-fpm', 'apache' and 'nginx' services.

Note: Setting value for max_execution_time parameter in PHP settings of a domain in Domains > example.com > PHP Settings will set the same value for FcgidIOTimeout parameter in virtual host configuration.

Have more questions? Submit a request
Please sign in to leave a comment.