采用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服務,問題成功結果。