get,post请求体超过nginx配置大小时,nginx会返回413,400,414等状态码

请求分为request_line,request_header,request_body,

requst_line与request_header策略相同,使用同一块buffer:

先以client_header_buffer_size分配buffer,
不足则进一步分配large_buffer;
又不足,则返回错误, request_line是 414 Request URI too large, request_header是 400 Bad Request;

Syntax:    client_header_buffer_size size;
Default:client_header_buffer_size 1k;
Context:    http, server

Syntax:    large_client_header_buffers number size;
Default:large_client_header_buffers 4 8k;
Context:    http, server
Buffers are allocated only on demand. By default, the buffer size is equal to 8K bytes. If after the end of request processing a connection is transitioned into the keep-alive state, these buffers are released.

操作系统中分页文件大小,通常是4k或8k;(请求行+请求头)的大小不能超过32k(4 * 8k); 如果一个连接请求将状态转换为 keep-alive,这个缓冲区将被释放;


request_body的策略则是 client_max_body_size 20M;不足则返回错误 413 Request Entity Too Large

request_body最大大小

Syntax:    client_max_body_size size;
Default: client_max_body_size 1m;
Context:    http, server, location

读取$request_body的内存buffer,HTTP BODY超过则写入磁盘临时文件

Syntax:    client_body_buffer_size size;
Default:  client_body_buffer_size 8k|16k;
Context:    http, server, location
Sets buffer size for reading client request body. In case the request body is larger than the buffer, the whole body or only its part is written to a temporary file. By default, buffer size is equal to two memory pages. This is 8K on x86, other 32-bit platforms, and x86-64. It is usually 16K on other 64-bit platforms.

开关,强制保存HTTP BODY$requst_body到临时文件$request_body_file,而不是$requst_body

Syntax:    client_body_in_file_only on | clean | off;
Default: client_body_in_file_only off;
Context:    http, server, location

off: 禁用文件写入
clean:请求body将被写入文件, 该文件将在处理请求后删除。
on: 请求正文将被写入文件, 处理请求后,将不会删除该文件。

当代理请求转发时,传递临时文件的名称,而不是文件的内容,建议以下配置禁用之:

When the name of a temporary file is passed in a proxied request or in a request to a FastCGI/uwsgi/SCGI server, passing the request body should be disabled by the 
proxy_pass_request_body off,
fastcgi_pass_request_body off,
uwsgi_pass_request_body off,
or scgi_pass_request_body off directives, respectively.

client_body_in_single_buffer: off;

设置NGINX将完整的请求主体存储在单个缓冲区中。 默认情况下,指令值为off。 如果启用,它将优化读取$request_body变量时涉及的I/O操作。

Syntax:    client_body_temp_path path [level1 [level2 [level3]]];
Default:client_body_temp_path client_body_temp;
Context:    http, server, location

比如 client_body_temp_path path 3 5; 生成的文件路径是 temp_files/123/12345/0000003051

指定存储请求正文的临时文件的位置。 除了位置之外,指令还可以指定文件是否需要最多三个级别的文件夹层次结构。 级别指定为用于生成文件夹的位数。 默认在安装路径下的client_body_temp文件夹创建临时文件

标签: none

添加新评论