title: Serving multiple node apps with nginx on same domain
body: <p>I would like to host 2 different node applications with nginx from the same domain and am having some trouble. I would like to have:</p>
  
  <p><em>mydomain.com</em> point to node app <strong>firstApp</strong> and <em>otherapp.mydomain.com</em> point to node app <strong>otherapp</strong></p>
  
  <p>Right now, I can access <strong>firstApp</strong> just fine, but I cannot access <strong>otherapp</strong> via otherapp.mydomain.com.</p>
  
  <p>My config for <strong>firstApp</strong> looks like this: </p>
  
  <pre><code>upstream firstApp{
      server 127.0.0.1:8123;
  }
  
  server{
      server_name mydomain.com;
      access_log /var/log/nginx/me.log;
  
      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://firstApp/;
          proxy_redirect off;
      }
  }
  </code></pre>
  
  <p>My config for <strong>otherapp</strong> looks like this:</p>
  
  <pre><code>upstream otherapp{
      server 127.0.0.1:8124;
  }
  
  server{
      server_name otherapp.mydomain.com;
      access_log /var/log/nginx/me.log;
  
      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://otherapp/;
          proxy_redirect off;
      }
  }
  </code></pre>
  
  <p>I have created both configurations in the nginx sites-available directory, they are both linked in the sites-enabled directory, and I have restarted nginx. Can someone tell me what I'm doing wrong?</p>
  
  <p>Thanks,
  Swaraj</p>