413 Request Entity Too Large nginx后台error.log报错client intended to send too large body
使用nginx,请求体大于1M时遇到这个报错:
413 Request Entity Too Large

查看nginx后台的error.log日志,也能看到如下的报错:
2025/04/17 10:11:15 [error] 28892#0: *1869247 client intended to send too large body: 2057300 bytes, client: 192.168.22.49, server: localhost, request: "POST /my_test HTTP/1.1", host: "10.10.22.212:60701"
客户端发送的请求体大小超过了 Nginx 配置的限制。默认情况下,Nginx 的请求体大小限制为 1MB。要解决问题需要添加配置:
client_max_body_size 128M;
此配置可以设置在多个位置,在http块中则对全局生效。

在server块中则对该server生效。

在location块中则只对该location生效。

如果多个位置同时配置了client_max_body_size,则以范围最小的为准。location块为最高优先,server块为次优先,http块为最低优先。
修改配置完成后,先检查配置文件语法是否有误:
./nginx -t
nginx: the configuration file /home/tong/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /home/tong/nginx/conf/nginx.conf test is successful
语法无误则重新加载使配置文件生效
./nginx -s reload

浙公网安备 33010602011771号