[Solution to the problem] 413 error 413 Request Entity Too Large The interface returns 413 and reports 413nginx


Blog background: JAVA project, the front end wanted to create a convenient rich text, so many pictures were directly converted to base64 encoding and stored directly. The field is of longtext type.
This problem usually occurs when the http request object is too large. .

Troubleshooting

1. If it is too long, change the varchar type to longtext type.
2. If you still doubt that it is too long, search the maximum length of longtext.

The maximum lengths of the three text types in mysql are as follows:
● TEXT 65,535 bytes ~64kb
● MEDIUMTEXT 16,777,215 bytes ~16Mb
● LONGTEXT 4,294,967,295 bytes ~4Gb

It was definitely not too long, so I went directly to read the request online. . Very direct. .
Need to modify the default size of nginx request

Insert image description here

solution

1. Modify the nginx configuration file nginx.conf

Limit the size of the request body, the default is 1m. If it exceeds the set size, a 413 error will be returned.

 client_max_body_size     50m; 

The timeout for reading request headers. If it exceeds the set size, a 408 error will be returned.

 client_header_timeout    1m;

The timeout for reading the request entity. If it exceeds the set size, a 413 error will be returned.

 client_body_timeout      1m;

The http request cannot be processed immediately by the container (tomcat, netty, etc.) and is placed in the nginx pending pool waiting to be processed. This parameter is the maximum waiting time. The default is 60 seconds. The official recommendation is that the longest time should not exceed 75 seconds.

 proxy_connect_timeout     60s;

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

 proxy_read_timeout      1m;

After the http request is processed by the server, the time it takes to return the data to Nginx is 60 seconds by default.

 proxy_send_timeout      1m;

(1) It can be set in http{ }: client_max_body_size 20m;
(2) It can also be set in server{ }: client_max_body_size 20m;
(3) It can also be set in location{ }: client_max_body_size 20m;

http{} controls all requests received by nginx.
If configured in server{}, it controls the size of request packets received by the server.
If configured in location, the packet size limit will only take effect for requests that match location routing rules.

nginx.conf file:

http{
    
    
#控制全局nginx所有请求报文大小
#client_max_body_size   20m;
                 server{
    
    
 #控制该server的所有请求报文大小
 #client_max_body_size   20m;
                         location a {
    
    
                         }
                         location b{
    
    
 #控制满足该路由规则的请求报文大小
 #client_max_body_size   20m;
                         }
                 }
                 server {
    
    
                 }
      }

2. After the update is completed, nginx needs to be restarted.

 sudo systemctl restart nginx

3. Other possibilities

Tomcat
In Tomcat's server.xml, the maxPostSize parameter will limit the maximum value of the post request message body. The default value is 2M (2097152 (2 megabytes).)
If it is not configured in server.xml, it is the default parameter value.

The front-end
node service uses the Egg.js framework, and Egg's configuration jsonLimit will limit the size of the json message body.
If not configured, the default is 100k.

Reference: https://blog.csdn.net/weixin_32006353/article/details/115981342
https://blog.csdn.net/z69183787/article/details/83070275

Guess you like

Origin blog.csdn.net/weixin_44436677/article/details/128124312