问题背景
在某系统中上传文件时,如果文件大小超过了一定范围就会爆 413 Request Entity Too Large 问题。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2f7724990ab6cfb65d48b595698c28c2.png)
原因
在使用 nginx 反向代理后台服务时,如果请求体中过大,超过了默认的 1M 则会爆该错误。
解决方案
在 nginx 中,指定配置文件 nginx.conf 中 http 中 client_max_body_size 10m; 然后重启 nginx即可。
注意,如果你是使用 spring 构建的项目,需要在相关服务的配置文件中指定 spring.servlet.multipart.max-file-size 属性和 nginx 中指定的一致,或者大于。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/520b813962df4d4d32d4a4dec7afcda1.png)