背景:由於上傳apk版本出現413的錯誤,同時報出跨域問題,但是測試環境沒有出現該問題
原因:因為生產環境請求的接口是nginx反向代理時后的域名。測試環境沒有配置nginx直接是ip+端口號請求。
解決方法:在ngixn.conf配置文件中添加 client_max_body_size屬性值。
Syntax: client_max_body_size size;
Default: client_max_body_size 1m; (默認是1M)
Context: http, server, location
Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field.
If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client.
Please be aware that browsers cannot correctly display this error.
Setting size to 0 disables checking of client request body size.
可以選擇在http{ }中設置:client_max_body_size 20m;
也可以選擇在server{ }中設置:client_max_body_size 20m;
還可以選擇在location{ }中設置:client_max_body_size 20m;
三者到區別是:http{} 中控制着所有nginx收到的請求。而報文大小限制設置在server{}中,則控制該server收到的請求報文大小,同理,如果配置在location中,則報文大小限制,只對匹配了location 路由規則的請求生效。