上传图片失败,前端报413 Request Entity Too Large
nginx默认上传文件的大小是 1M ,修改nginx.conf中的 http{} 代码快设置为10m
client_max_body_size 10m;
重启nginx命令
新增配置:
1、进入Nginx目录conf下的nginx.conf
cd /usr/local/nginx/conf/
2、编辑文件
vim nginx.conf
3、找到http{...},在大括号中新增配置(注意最后要有分号;)
client_max_body_size 20m;
重启Nginx服务:
1、首先进入安装Nginx目录
cd /usr/local/nginx/sbin/
2、重启Nginx服务
./nginx -s reload
重启nginx之后后端报错Maximum upload size exceeded;
文件超 1M 但小于 10M 时的异常信息:
Resolved [org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.]
文件超 10M 的异常信息:
Resolved [org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (12209424) exceeds the configured maximum (10485760)]
解决方案
yml配置:
spring:
servlet:
multipart:
# 单个文件最大大小
max-file-size: 50MB
# 所有上传文件最大大小
max-request-size: 50MB
application.properties配置
spring.servlet.multipart.max-file-size=50MB
spring.servlet.multipart.max-request-size=50MB
问题解决。