To upload pictures to nodejs(on a dev machine) I use the following approach:

var http=require('http'),
    path=require('path'),
    os=require('os');

function(req, res) {
    var busboy=new Busboy({headers: req.headers});
    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
      var saveTo=path.join(os.tmpDir(), path.basename(fieldname));
      file.pipe(fs.createWriteStream(saveTo));
    });
    busboy.on('finish', function() {
      res.writeHead(200, {'Connection':'close'});
      res.end("That's all folks!");
    });
    return req.pipe(busboy);
  }
  res.writeHead(404);
  res.end();
}


The production server costs nginx and I need to understand how to configure it so that, on the nodejs side, performance is not lost and the ability to stream files is preserved.

nginx proxies requests from NodeJS as follows:

upstream node_upstream {
    server 127.0.0.1:35000;
    keepalive 64;
}

server {
    listen 80;

    location/{
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Connection"";
        client_max_body_size 10m;
        client_body_buffer_size 128k;
        proxy_http_version 1.1;
        proxy_pass http://node_upstream;
        proxy_intercept_errors on;
    }
}


Tell me how to properly configure nginx to stream files using nodejs?

1 Answers 1

Look towards using a specialized module for Nginx and Node.js interaction - Phusion Passenger.Everything should be in order with similar optimization without any additional settings, according to the idea.Architecture and settings documentation, if that - very detailed.