Nginx 413 Request Entity Too Large
1. 简述
在通过网页上传文件时,通过浏览器开发者工具查看发现后台响应状态码413 Request Entity Too Large,但在检查后台Server时确发现没有收到请求。

正常请求会经过1、2、3、4步聚,但此次请求只经过1、4步聚,检查Nginx发现下面日志信息。
2021/03/30 15:58:52 [error] 30#30: *32 client intended to send too large body: 18790901 bytes, client: xxxx, server: xxxx, request: "PUT /ks/note/save/00000000-0000-0000-0000-000000000000/22de72ba-fa76-4dee-ab8d-f3b974849a3a?clientType=web&clientVersion=4.0&lang=zh-cn HTTP/1.1", host: "xxxx", referrer: "https://xxxx/wapp/recent/00000000-0000-0000-0000-000000000000?l=zh-cn&clientType=macosx&clientVersion=2.8.7&p=wiz&docGuid=22de72ba-fa76-4dee-ab8d-f3b974849a3a"
2. 原因
因为上传文件时的请求body超过Nginx默认的1m大小限制,被 Nginx 给拦截了,下面是 Nginx 这部分官方文档信息,参考地址见末尾。
官方示例
Syntax: client_max_body_size size;
Default:
client_max_body_size 1m;
Context: http, server, location
Sets the maximum allowed size of the client request body. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.
3. 解决方法
在http, server, location中的任一一处添加下面内容。
client_max_body_size 100m;
当尝试上传大文件时遇到Nginx返回413 Request Entity Too Large错误,原因是请求体超过了Nginx默认1M的限制。解决办法是在Nginx配置中增加client_max_body_size设置,例如设置为100M,以允许更大的文件上传。
201

被折叠的 条评论
为什么被折叠?



