Sometimes the long running requests failed with the error message “504: Gateway Timeout” in NGINX web server. To solve this issue, you need to increase request timeout in NGINX server configuration. The default, NGINX request timeout is 60 seconds. Which can be increased or decreased by updating the configuration files.

In this quick FAQ, you will learn to change the request timeout in NGINX web server.

Increase Request Timeout in NGINX

For example, you want to increase request timeout to 300 seconds. Then you need to add proxy_read_timeout, proxy_connect_timeout, proxy_send_timeout directives to http or server block. Here the http block allows the changes in all server in NGINX.

To make changes for all servers, edit the NGINX main configuration file and add the following content under http block.

http{
   ...
   proxy_read_timeout 300;
   proxy_connect_timeout 300;
   proxy_send_timeout 300;
   ...
}

In case, you just want to increase request timeout for a specific server or subdomain, then add the directives for its server block only. Edit the specific server block configuration file and add the following settings:

server{
   ...
   proxy_read_timeout 300;
   proxy_connect_timeout 300;
   proxy_send_timeout 300; 
   ...
}

After making the changes, you must restart the NGINX service to apply changes. The systems running with Systemd can use the following command.

sudo systemctl restart nginx 

All done, With the above changes, you have successfully increased the request timeout in NGINX server.

Conclusion

This tutorial helps you to increase request timeout in NGINX web server.