采用Django开发的后端服务器,有一个开放的API是用于文件上传的,在生产环境上一直没问题,但有一天收到反馈说调用这个接口反馈了413错误:
<html>
<head>
<title> Request Entity Too Large</title>
</head>
<body bgcolor="white">
<h1> Request Entity Too Large</h1>
<P>The requested resource does not allow request data with the requested method or the amount of data provided in the request exceeds the capacity limit. Sorry for the inconvenience.
<br/>
Please report this message and include the following information to us.
<br/>
Thank you very much!
</p>
</body>
</html>
查询得知,这个413的意思是请求实体太大,应为这个接口是上传文件用的,显然指的是文件的大小超出了限制。
回顾了后端代码,并没有对上传文件的大小做任何限制,自己调试的时候也没有碰到过这个问题,想到生产环境用的是Nginx做代理,所以很有可能问题出在Nginx配置上。
在Nginx的配置文件中找到这样一行:
client_max_body_size 2m;
果然是Nginx做了限制,默认的上限是2M,把这个参数适当调整后重启Nginx服务,问题成功结果。