Nginx upload large file timeout solution

  • 2020-05-13 04:34:52
  • OfStack

Nginx upload large files timeout solution

The situation is as follows: when using nginx as the proxy server, when uploading a large file (I tested the file uploaded by 50m), it will prompt the upload timeout or the file is too large.

The reason is that nginx has a limit on the size of uploaded files, and the default is 1M. In addition, if the file is large, you should adjust the upload timeout.

The solution is to add the following configuration to the nginx configuration file:


client_max_body_size     50m; // File size limit, default 1m
client_header_timeout    1m; 
client_body_timeout      1m; 
proxy_connect_timeout     60s; 
proxy_read_timeout      1m; 
proxy_send_timeout      1m;



Meaning of each parameter:

client_max_body_size

Limit the size of the request body, return 413 error if it exceeds the specified size.

client_header_timeout

Read the timeout of the request header and return a 408 error if the specified size is exceeded.

client_body_timeout

Read the timeout for the requested entity and return a 413 error if the specified size is exceeded.

proxy_connect_timeout

The http request cannot be processed immediately by the container (tomcat, netty, etc.) and is placed in the nginx pool to be processed. This parameter is the maximum time to wait, the default is 60 seconds, the official recommendation is no more than 75 seconds.

proxy_read_timeout

After the http request is processed by the container (tomcat, netty, etc.), nginx waits for the processing result, which is response returned by the container. This parameter is the server response time, which defaults to 60 seconds.

proxy_send_timeout

When the http request is processed by the server, the default time for sending the data back to Nginx is 60 seconds.

The above is to nginx upload large files timeout solution details, if you have any questions please leave a message or to the site community exchange discussion, thank you for reading, hope to help you, thank you for the support of the site!


Related articles: