title: Node.js on multiple domains using express.vhosts()
body: <p>I'm back here with a nodejs problem, I am writing a node server that allows two or more app.js running on the same system using express.vhost(). But I'm quite lost now.</p>
  
  <p>The webhost server is a dedicated server running Ubuntu and plesk and I've assigned 2 ip's for different domains.</p>
  
  <p>xxx.xxx.xxx.123 IP is assigned to domain-one.com
  xxx.xxx.xxx.xxx.456 is assigned to domain-two.com</p>
  
  <p>both run a nodejs server app.js
  and are each allocated in /var/www/vhosts/[domain-name]/node/app.js</p>
  
  <p>The server running the vhost is at /var/www/node/server.js here is the code</p>
  
  <pre><code>var express = require("express");
  var app = express();
  
  app
  .use(express.vhost('domain-one.com', require('/var/www/vhosts/domain-one.com/node/app.js').app))
  .use(express.vhost('domain-two.com', require('/var/www/vhosts/domain-two.com/node/app.js').app))
  .listen(3030);
  
  
  app.get('/', function(req, res){
    res.send('hello world the server running ');
  });
  </code></pre>
  
  <p>While in each app.js</p>
  
  <pre><code>var express = require('express'),
      routes  = require('./routes');
  
  var app = exports.app = express.createServer();
  
  app.get('/', function(req, res){
    res.send('hello world test file for [domain-name] running');
  });
  
  //port 3031 for domain-one.com
  //port 3032 for domain-two.com
  app.listen(3031); 
  </code></pre>
  
  <p>then i run node server.js and every thing works fine without errors.</p>
  
  <p>then i run a <em>netstat -anltp</em></p>
  
  <pre><code>tcp        0      0 0.0.0.0:3030            0.0.0.0:*               LISTEN      19839/node      
  tcp        0      0 0.0.0.0:3031            0.0.0.0:*               LISTEN      19839/node      
  tcp        0      0 0.0.0.0:3032            0.0.0.0:*               LISTEN      19839/node  
  </code></pre>
  
  <p>Ok everything goes as i expected (i suppose)  so i open my browser and type  <em>domain-one.com:3031</em> and in other tab domain-two.com:3032</p>
  
  <p>but drops a Connection time-out in both domains... and when i run domain-one.com:3030 it displays the: </p>
  
  <blockquote>
    <p>hello world the server running</p>
  </blockquote>
  
  <p>But not in domain-two.com:3030 it hangs also..</p>
  
  <p>I, want to get my head around this and understand a bit about how my server and domains work and how to manage to run diferent nodejs apps for diferent ip/domains in my server... </p>
  
  <p>somethimes the domain-two.com prints what the domain-one.com app.js file res.send() supposed to print on the other domain...</p>
  
  <p>I guess im very confused now... hope you can help me out with this..</p>
  
  <p>Thanks a lot</p>
  
  <p>-ivan</p>