I have set up a NGINX server as well as a node.js process. The node.js code looks something like this:
function startCluster() {
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
} else {
// begin
var server = app.listen(3000, function() {
console.log('Listening on port %d', server.address().port);
});
}
}
startCluster();
The NGINX config is using proxy_pass to relay all incoming requests to node on port 3000.
When a server starts I have some 3-4 NGINX processes and 5-6 Node processes. (though I imagine that number might increase or decrease depending on the server load)
Question: How does node's cluster work with NGINX's proxy_pass and does it require any extra configuration?
Or does NGINX simply pass requests to port 3000 and then nodejs takes over the rest?