我有这个由Nginx代理的node.js应用程序(正在制作中).路线是这样的:
exports.download = function(req,res){
var id = req.params.id;
if (id && id == 'latest')
{
res.download(config.items.release_directory+'/<1.6GB-file>.zip',function(err){
if (err) {
console.log(err);
} else {
// do something
}
});
}
else
{
res.redirect(301,'/');
}
};
因此,单击正确的路径/ URL,浏览器开始下载大文件,但随后它始终停止在1.08GB(文件大约为1.6GB),截断它.
我真的不明白为什么.有任何想法吗?
编辑:
config.items.release_directory是一个静态Express目录,声明为:
app.use('/releases',express.static(path.join(__dirname,'..','releases')));
EDIT2:
在没有Nginx的情况下使用grunt直接服务应用程序的开发它可以正常工作.
求助:阅读下面的评论,问题是Nginx中的proxy_max_temp_file_size变量
最佳答案
这里的问题是nginx配置,而不是nodejs代码.
nginx在将临时文件发送到客户端之前将其写入磁盘,如果站点要提供大型静态文件,通常最好禁用此缓存,例如:
location / {
proxy_max_temp_file_size 0;
}
(没有限制)