Nginx configuration file upload

Time:2021-11-29

Nginx problem

Problems encountered:

  • Nginx: 413 – Request Entity Too Large Error and Solution
  • TIMEOUT

resolvent

Solution: under the configuration file of nginx (usually XXX. CONF), add the following configuration:

client_ max_ body_ size     50m;  #  Limit the size of the request body. If it exceeds the set size, a 413 error will be returned. The default is 1m
client_ header_ timeout    1m;  #  If the timeout of reading request header exceeds the set size, 408 error will be returned
client_ body_ timeout      1m; #  If the timeout of the read request entity exceeds the set size, a 413 error is returned
proxy_ connect_ timeout     60s; #  HTTP requests cannot be immediately processed by containers (tomcat, netty, etc.), and are placed in the pending pool of nginx for processing. This parameter is the maximum waiting time, the default is 60 seconds, and the official recommended maximum is no more than 75 seconds
proxy_ read_ timeout      1m;  #  After the HTTP request is processed by the container (tomcat, netty, etc.), nginx will wait for the processing result, that is, the response returned by the container. This parameter is the server response time, which is 60 seconds by default
proxy_ send_ timeout      1m; #  After the HTTP request is processed by the server, it takes 60 seconds by default to send the data back to nginx
server {
    listen       80;
    server_name  localhost;
    
    client_max_body_size     10m;
    client_header_timeout    5m;
    client_body_timeout      5m;
    proxy_connect_timeout     6000s;
    proxy_read_timeout      5m;
    proxy_send_timeout      5m;

    location  / {
        # ...
    }
}    

Restart nginx

After setting, you need to usereloadperhapsreloadRestart nginx