Friday, 15 April 2011

Muitliple Node.js servers using NGINX proxys -



Muitliple Node.js servers using NGINX proxys -

the goal:

use muitiple live node.js servers independent of each other under different doc roots.

using nginx server { server_name .lolwut1.com; root /var/www/html/lolwut1; # proxy pass nodejs location / { proxy_pass http://127.0.0.1:5001/; } } server { server_name .lolwut2.com; root /var/www/html/lolwut2; # proxy pass nodejs location / { proxy_pass http://127.0.0.1:5002/; } } /var/www/html/lolwut1/app.js var http = require('http'); var server = http.createserver(function (request, response) { response.writehead(200, {"content-type": "text/plain"}); response.end("lolwut1\n"); }); server.listen(5001); /var/www/html/lolwut2/app.js var http = require('http'); var server = http.createserver(function (request, response) { response.writehead(200, {"content-type": "text/plain"}); response.end("lolwut2\n"); }); server.listen(5002); so when i...

node app.js in /var/www/html/lolwut1/app.js , nail lolwut1.com i'm good.

questions: but if want start sec node server? is bad approach?... thinking wrong way? what advantages/disadvantages of using node.js connect.vhost directive router rather nginx?

use forever start , stop node apps. you're doing right! approach has worked me quite while.

connect vhost advantage: don't have install , configure nginx. whole stack node.js.

nginx advantage: nginx mature , stable web server. it's unlikely crash or exhibit unusual behavior. can host static site, php site, etc.

if me, unless needed particular feature of nginx, i'd pick connect vhost or node-http-proxy sake of having all-node.js stack.

node.js nginx

No comments:

Post a Comment