实例迁移之后,Nginx 上传附件失败,提示:
413 Request Entity Too Large
原因:nginx 附件上传不上去 client_max_body_size 设置的太小,修改nginx配置
client_max_body_size 20m;
然后重启nginx
systemctl restart nginx.service
Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field.
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.
设置如下:
Syntax: | client_max_body_size |
---|---|
Default: | client_max_body_size 1m; |
Context: | http , server , location |
可以选择在http{ }中设置:client_max_body_size 20m;
也可以选择在server{ }中设置:client_max_body_size 20m;
还可以选择在location{ }中设置:client_max_body_size 20m;
三者到区别是:http{} 中控制着所有nginx收到的请求。而报文大小限制设置在server{}中,则控制该server收到的请求报文大小,同理,如果配置在location中,则报文大小限制,只对匹配了location 路由规则的请求生效。
参考文档:https://www.nginx.cn/doc/standard/httpcore.html
本文为崔凯原创文章,转载无需和我联系,但请注明来自冷暖自知一抹茶ckhttp://www.cksite.cn