nginx: client intended to send too large body

When uploading a file larger than 1M recently, an error was reported to nginx.

413 Request Entity Too Large

Modify nginx configuration after investigation

This is the simplest method. The reason for the error is that nginx does not allow uploading files with too large configuration, so just increase the upload size configuration of nginx.

1. Open the nginx main configuration file nginx.conf, find the http{} section and modify the following content:

client_max_body_size 15m;
client_body_buffer_size 15m;

2. Add the timeout time to nginx.conf (you can configure it in http{}).
When nginx uses the proxy module, the default read timeout time is 60s.

Configure nginx upload file size limit

client_max_body_size 15m;
client_body_buffer_size 15m;
 # 超时时间
proxy_connect_timeout       300s; //后端服务器连接的超时时间_发起握手等候响应超时时间
proxy_send_timeout          300s;  //后端服务器数据回传时间_就是在规定时间之内后端服务器必须传完所有的数据
proxy_read_timeout          300s; //也可以说是后端服务器处理请求的时间
send_timeout                300s; //传输响应给客户端的超时时间
fastcgi_connect_timeout 300; //指定nginx与后端fastcgi server连接超时时间
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;

extensions:
syntax: keepalive_timeout timeout [header_timeout];
default: keepalive_timeout 75s;
context: http, server, location

The first parameter sets the timeout during which keep-alive client connections will remain open on the server side. A value of zero disables keep-alive client connections.

The optional second parameter sets a value in the "Keep-Alive: timeout=time" response header field. The two parameters may be different.

The "Keep-Alive: timeout=time" header field is recognized by Mozilla and Konqueror. MSIE closes keep-alive connections by itself in about 60 seconds.

Syntax: send_timeout time;
Default: send_timeout 60s;
Context: http, server, location

Sets the timeout for transmitting responses to the client. The timeout is only set between two consecutive write operations, not for the transmission of the entire response. If the client does not receive any messages within this time, the connection is closed.

So when using keepalive_timeout, the browser does not have to make multiple connections, but uses the already established connection. This controls how long to keep alive/open.

I suggest that if you set the send_timeout to small the web server will close connections quickly which will give more overall connections available to the connecting host.

These parameters are likely only relevant for high traffic web servers, both support the same goals: fewer connections and more efficient request processing, either put all requests into one connection (keep alive) or close the connection quickly to handle more Multiple requests (send timeout)).

3. All the above configurations did not take effect.
The reason is that we used k8s container management, and the nginx mirror configuration was modified by some colleague, and the external nginx.conf configuration file was not mounted to the mirror at all.
insert image description here
Then mount it to the mirror and restart nginx to solve it.

Guess you like

Origin blog.csdn.net/qq_38747892/article/details/131330015