Fix 504 Gateway Timeout error using Nginx as reverse Proxy.

When using Nginx as a reverse proxy for Apache, among others, you may get timeouts with error code 504 if an application takes longer to complete a request than the default Nginx request timeout which is 60 seconds. To increase the request timeout in Nginx to serve long-running requests, we need to change the default settings.

This tutorial requires you to be logged in as root, so switch to root user if you are not already.

$ sudo -i

Create a new file timeout.conf in the “/etc/nginx/conf.d/” directory.

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

Add the following code:

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

Here we have increased the timeout to 600 seconds, but you can change it to suit your needs.

For the new settings to take effect a restart of Nginx is required.

# systemctl restart nginx

Similar Posts