上傳文件返回413錯誤同時出現has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header...


背景:由於上傳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 路由規則的請求生效。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 【跨域問題】Access to XMLHttpRequest at ‘A’from ‘B’has been blocked by CORS policy :... No ‘Access-Control-Allow-Origin’ header...(Chrome瀏覽器) 前端出現has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is 跨域詳解 been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource 跨域詳解 been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource Access to XMLHttpRequest at 'XXX' from origin 'XX' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present o AJAX跨域請求解決方法 has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Access to XMLHttpRequest at '*url*' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. GET *url* net::ERR_FAILED Access to XMLHttpRequest at 'http://localhost:8090/user/getotp' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM