SoFunction
Updated on 2025-04-08

Implementation of Nginx setting response timeout configuration

1. Find configuration files

To find Nginx's configuration files, there are usually several places to view, because Nginx's configuration files can be distributed in multiple locations. Here are some common steps and locations to find Nginx configuration files:

Global configuration file:

The main configuration files for Nginx are usually. On most Linux systems, this file is located in the /etc/nginx/ or /usr/local/nginx/conf/ directory.

You can use the ls command to view files in these directories:

ls /etc/nginx/

# or

ls /usr/local/nginx/conf/

Then use the cat or less command to view the contents of the file:

cat /etc/nginx/

# or

less /etc/nginx/

Site configuration file:

In addition to global configuration files, Nginx allows you to create independent configuration files for specific sites or applications. These files are usually located in the /etc/nginx/sites-available/ (for Debian and Ubuntu systems) or the /etc/nginx// (for other systems) directory.

You can view files in these directories using the following command:

ls /etc/nginx/sites-available/

# or

ls /etc/nginx//

You can then use the cat or less command to view the configuration file contents of a specific site.

Includes files:

In or in the site configuration file, you may see the include directive that tells Nginx to include other configuration files. These files may contain additional server blocks, location blocks, or variable definitions. You need to follow the path specified in the include directive to find these files.

Find the Nginx command:

If you are not sure where the Nginx configuration file is exactly located, you can try using the find command to search the entire file system. But be aware that this may take some time and may return a lot of irrelevant results.

sudo find / -name  2>/dev/null

Note: 2>/dev/null is used to discard permission errors and other irrelevant output.

2. Modify the configuration file

As a high-performance HTTP and reverse proxy server, Nginx's stability and performance depend heavily on its timeout setting. This article will explain the various timeout settings of Nginx in detail and provide some suggestions to help you adjust according to the actual situation to ensure efficient and stable operation of Nginx.

2.1. Client timeout setting

2.1.1 client_header_timeout

This setting defines the timeout for Nginx to wait for the client to send the full request header. By default, this value is 60 seconds. If the client does not send the request header within this time, Nginx will return a 408 (Request Time-out) error.

2.1.2 client_body_timeout

This setting defines the timeout for Nginx to wait for the client to send the complete request body. By default, this value is also 60 seconds. This timeout refers to the interval between two successful read operations, rather than the sending time of the entire request body. If the client does not send any request body during this time, Nginx will return a 408 (Request Time-out) error.

2.2. Proxy timeout setting

When Nginx is a reverse proxy server, you also need to consider the proxy timeout setting. This includes the timeout time for sending a request to the backend server and the timeout time for receiving a response from the backend server.

2.2.1 proxy_send_timeout

This setting defines the timeout for Nginx to send requests to the backend server, including the time when the request header and the request body are sent. By default, this value is not set, which means Nginx will wait for the backend server to respond indefinitely. However, to avoid potential problems, it is recommended to set a reasonable value, such as 10 seconds.

If the backend server cannot respond within this time, Nginx will return a 504 (Gateway Time-out) error.

2.2.2 proxy_read_timeout

This setting defines the timeout for Nginx to receive responses from the backend server. By default, this value is not set. To ensure stable operation of Nginx, it is recommended to set a reasonable value, such as 10 seconds.

If the backend server cannot return a response within this time, Nginx will close the connection and return a 504 (Gateway Time-out) error.

2.3. FastCGI timeout setting

In addition to client and proxy timeout settings, Nginx also supports the FastCGI protocol and needs to set the corresponding timeout time.

2.3.1 fastcgi_send_timeout

This setting defines the timeout for Nginx to send requests to the FastCGI process. By default, this value is not set. To avoid potential problems, it is recommended to set a reasonable value, such as 30 seconds.

If the FastCGI process cannot respond within this time, Nginx will close the connection.

2.3.2 fastcgi_read_timeout

This setting defines the timeout for Nginx to receive responses from the FastCGI process. By default, this value is not set. To ensure stable operation of Nginx, it is recommended to set a reasonable value, such as 60 seconds.

If the FastCGI process cannot return a response within this time, Nginx will close the connection.

3. Restart the service

In Linux systems, the method of restarting Nginx services depends on whether your system uses Systemd or scripts. Here are two common methods:

If your system uses Systemd (most modern Linux distributions, such as Ubuntu 16.04 and later, CentOS 7 and later, etc.):

sudo systemctl restart nginx

If your system uses scripts (older Linux distributions):

sudo service nginx restart

Or, if you need to use the commands that come with Nginx, you can use:

sudo nginx -s reload

This command will cause Nginx to reload the configuration file instead of restarting completely. This is usually used in cases where the current connection is not interrupted after a configuration is changed.

This is the end of this article about the implementation of Nginx setting response timeout configuration. For more related Nginx response timeout content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!