Nginx服务器上运行基于SrpingBoot的WebApi服务(服务端已设置最大可上传50M),通过前端上传一个超过10M的文件,出现以下提示:
原因分析
查看Nginx 关于client_max_body_size的描述
http服务客户端最大上传默认设置为1M
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, 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.
解决办法
修改nginx.conf配置文件,增加client_max_body_size大小。
http {
...
# set client body size to 50M #
client_max_body_size 50m;
include /etc/nginx/mime.types;
default_type application/octet-stream;
...
}
测试
上传13M的文档
上传成功
此篇文章由DurkBlue发布,感谢转载需要请注明来处