Running multiple sites on node.js

I plan to make three sites using node.js. I have some common patterns among sites. Should I run all three sites in one instance of node.js?

I know about the "vhost" middleware, which allows you to run multiple domains on the same http server. Is there a better way to do this?

I also have static html templates and not sure how to deal with them in node.js?

Finally, I would like to know the hosting options for this kind of settings?

+7
source share
1 answer

I myself just had to do the same. What you want to do is use some kind of reverse proxy.

I use here: https://github.com/nodejitsu/node-http-proxy

Just install the proxy package: npm install http-proxy

I have a proxy server running on a server on port 80. I set DNS in each domain to point to this server.

Each application runs on one server (im uses screens).

For example:

 MySiteApplication1 - 3001 MySiteApplication2 - 3002 MySiteApplication3 - 3003 

Then your proxy file will look like this

 var httpProxy = require('http-proxy'); var server = httpProxy.createServer({ router: { 'mysite1.com': 'localhost:3001', 'mysite2.com': 'localhost:3002', 'mysite3.com': 'localhost:3003' } }); server.listen 80 
+14
source

All Articles