Nginx node.js express download big files stop at 1.08GB

纵然是瞬间 提交于 2020-01-01 11:59:06

问题


I have this node.js app proxied by Nginx (on production). A route is something like this:

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, '/');
    }

};

So, clicking the right route/URL the browser starts to download the big file but then it stops always at 1.08GB (the file is about 1.6GB), truncating it.

I really cannot understand why. Any ideas?

EDIT: The config.items.release_directory is a static Express directory declared as:

app.use('/releases', express.static(path.join(__dirname, '..', 'releases')));

EDIT2: On development with grunt serving directly the app without Nginx it works fine.

SOLVED: read the comments below, problem is proxy_max_temp_file_size variable in Nginx


回答1:


Here the matter is nginx configuration, not nodejs code.

nginx write temp files in disk before sending them to the client, it's often a good idea to disable this cache if the site is going to serve big static files, with something like:

location / {
    proxy_max_temp_file_size 0;
}

(no limit)




回答2:


In case of uploading a file while proxying with Nginx, you can set "max body size" inside of you server{} block in Nginx config:

client_max_body_size 0; # disable any limits to avoid HTTP 413

If you are getting HTTP 413, check your Nginx config and either set it to zero or crank it up, accordingly.

Otherwise, I'd try to increase some timeouts, such as these:

send_timeout 600s; # default is 60s; context: http, server, location

proxy_read_timeout 600s; # default is 60s; context: http, server, location
proxy_send_timeout 600s; # default is 60s; context: http, server, location

For more proxy options, checkout Nginx Proxy module documentation (link).



来源:https://stackoverflow.com/questions/25039916/nginx-node-js-express-download-big-files-stop-at-1-08gb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!