title: how to install multiple nodejs app with multiple domains?
body: <p>i read more than ever in this time, this will be my first webpage so i decided mount on nodejs. I make the app very quickly and i test in localhost:9000</p>
  
  <p>so i want to put more apps running on a VPS, i search information and i have two options</p>
  
  <p>first use nginx to proxy the apps...</p>
  
  <pre><code>upstream example1.com {
      server 127.0.0.1:3000;
  }
  
  server {
  listen   80;
  server_name  www.example1.com;
  rewrite ^/(.*) http://example1.com/$1 permanent;
  }
  
  # the nginx server instance
  server {
      listen 80;
      server_name example1.com;
      access_log /var/log/nginx/example1.com/access.log;
  
      # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
      location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
  
        proxy_pass http://example1.com;
        proxy_redirect off;
      }
   }
  </code></pre>
  
  <p>i dont understand this config file because i never use nginx so i search a second option</p>
  
  <p>using vhost from expressjs()</p>
  
  <pre><code>express()
  .use(express.vhost('m.mysite.com', require('/path/to/m').app))
  .use(express.vhost('sync.mysite.com', require('/path/to/sync').app))
  .listen(80)
  </code></pre>
  
  <p>im using expressjs and i understand how to configure, but there are some questions about wich is the best option because using express() i have one app managing multiple apps so i think it is not a good practice and a waste of resources.</p>
  
  <p>from <a href="https://stackoverflow.com/questions/9332865/how-should-i-organize-multiple-express-servers-on-the-same-system">this</a> post, David Ellis says</p>
  
  <p>If you don't need to use WebSockets (or any HTTP 1.1 feature, really), you can use NginX as your proxy instead.</p>
  
  <p>The advantage is the total load NginX can handle versus Node is higher (being statically compiled and specialized for this sort of thing, basically), but you lose the ability to stream any data (sending smaller chunks at a time).</p>
  
  <p>For a smaller site, or if you're unsure what features you'll need in the future, it's probably better to stick with node-http-proxy and only switch to NginX if you can demonstrate the proxy is the bottleneck on your server. Fortunately NginX isn't hard to set up if you do need it later.</p>
  
  <p>and from <a href="https://serverfault.com/questions/414263/configure-nginx-for-multiple-node-js-apps-with-own-domains">this</a> post i read an example to configure xginx with many apps but i dont understand how to use that for me</p>
  
  <pre><code>upstream example1.com {
      server 127.0.0.1:3000;
  }
  
  server {
  listen   80;
  server_name  www.example1.com;
  rewrite ^/(.*) http://example1.com/$1 permanent;
  }
  
  # the nginx server instance
  server {
      listen 80;
      server_name example1.com;
      access_log /var/log/nginx/example1.com/access.log;
  
      # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
      location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
  
        proxy_pass http://example1.com;
        proxy_redirect off;
      }
   }
  
  upstream example2.com {
      server 127.0.0.1:1111;
  }
  
  server {
  listen   80;
  server_name  www.example2.com;
  rewrite ^/(.*) http://example2.com/$1 permanent;
  }
  
  # the nginx server instance
  server {
      listen 80;
      server_name example2.com;
      access_log /var/log/nginx/example2.com/access.log;
  
      # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
      location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
  
        proxy_pass http://example2.com;
        proxy_redirect off;
      }
   }
  </code></pre>
  
  <p>so the question is wich is the best option, use nginx or use vhost???</p>
  
  <p>if i have to use nginx there is any tutorial how to configure nginx to serve many apps on node js??? </p>
  
  <p>tnx all</p>