在上传文件时提示该错误,原因在于文件大小超出了预先设置的文件上传大小。
解决方案:
第一步:修改 spring-mvc 配置文件
<!-- 文件上传解析器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<!-- 指定所上传文件的总大小104857600=1024*102400K即100M-->
<property name="maxUploadSize" value="104857600"></property>
<property name="maxInMemorySize" value="40960"></property>
</bean>
第二步:修改 nginx.conf 配置文件(nginx为yum安装)
1 . 打开 nginx.conf 文件:/etc/nginx/nginx.conf
在http{ }处 ,添加 / 修改 以下内容:
client_max_body_size 100m; //设置允许文件上传的大小为100M
2 . 测试nginx配置是否正确
进入sbin文件夹,输入命令:./nginx -t
3 . 重启nginx
进入sbin文件夹,输入命令:./nginx -s reload
其他:
文件位置 / 安装方式 | sbin文件(启动目录) | conf文件(配置文件目录) |
---|---|---|
编译安装 | /usr/local/nginx/sbin/nginx | /usr/local/nginx/conf/nginx.conf |
yum安装 | /usr/sbin/nginx | /etc/nginx/nginx.conf |