How to set the timeout for nginx?

The timeout settings can be adjusted in the nginx configuration file by modifying the following two parameters.

  1. proxy_connect_timeout: Used to set the timeout for establishing a connection with the upstream server (such as a reverse proxy server). The default value is 60 seconds, but can be adjusted as needed.
  2. proxy_read_timeout: This is used to set the timeout for reading a response from the upstream server. The default value is 60 seconds, but it can be adjusted as needed.

Here is an example configuration where the proxy_connect_timeout is set to 10 seconds and the proxy_read_timeout is set to 20 seconds:

http {
    ...
    proxy_connect_timeout 10s;
    proxy_read_timeout 20s;
    ...
}

In the aforementioned settings, ‘s’ stands for seconds. The timeout value can be adjusted according to the actual needs. After completing the configuration, restart the nginx service for the changes to take effect.

bannerAds