L
L
likejavascript2015-01-10 14:33:17
Nginx
likejavascript, 2015-01-10 14:33:17

How to properly configure nginx to load images in conjunction with the nodejs pipe?

To load images in 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();
}

There is nginx on the production server and I need to understand how to set it up so that performance is not lost on the nodejs side and the ability to stream files is preserved.
nginx proxy requests from NodeJS like this:
upstream node_upstream {
    server 127.0.0.1:3000;
    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 file uploads using nodejs?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question