Failed to load resource the server responded with a status of 413 (Request Entity Too Large)
程序员文章站
2024-02-01 21:34:10
...
Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)问题解决方案
错误描述:
Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)
常见错误原因:
由于Nginx反向代理服务器client_max_body_size
默认值为1MB,而上传文件大于1MB
常用解决方案:
打开Nginx反向代理服务器nginx.conf配置文件,修改client_max_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 路由规则的请求生效。
本次错误分为两个部分
首先是项目中设置了默认文件上传大小限制
var size = fileObj.size;
var name = fileObj.name;
var sizeLimit = opts.fileSizeLimit;
if(sizeLimit){
if(parseInt(sizeLimit)*1024*1024 < size){
return ["1","您上传的附件"+name+"超出了"+sizeLimit+"M"];
}
}
在调用该方法时,需要传递fileSizeLimit值,以防止超出默认文件大小
$.ajaxFileUpload({
type: 'POST',
url: "/saleCenterApp/unitChangeTemplateUploadFile", // 上传文件公共方法
secureuri: false,
enctype: "multipart/form-data",
fileElementId: id, // 文件选择框的id属性
dataType: 'json',
data: {},
success: function (data) {
loading.close();
subpluspop.warn("上传成功!", 3000);
},
error: function (data) {
loading.close();
subpluspop.warn("上传失败!", 3000);
}
});
其次Nginx中没有对client_max_body_size进行修改,修改路径如下.\node_modules\fis\node_modules\fis-command-server\lib\nginx\conf\nginx.bak
,在location /saleCenterApp中添加client_max_body_size 1000m;
推荐阅读
-
Failed to load resource the server responded with a status of 413 (Request Entity Too Large)
-
上传图片报错-Failed to load resource:the server responded with a status of 413(Request Entity Too Large)
-
Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)【上传图片】
-
【Nginx】Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)
-
Failed to load resource:the server responded with a status 413 (Request Entity Too Large)