title: Nginx with 1 domain, 2 apps. Ror + nodejs
body: <p><br>
  Hey.<br>
  After a few hours of research I couldn't find any easy how-to solutions for my problem.</p>
  
  <p>I have written earlier a RoR app that's deployed on my server and running just fine. Now I'm trying to deploy also a Nodejs app to run alongside my RoR app. The two apps don't have anything to do with each other - they are to be used separately.</p>
  
  <p>I only have one domain to use and I'm trying to use Nginx.
  The RoR app is running on Unicorn + Nginx already.</p>
  
  <p>My first question is what is the correct way to deploy two separate apps alongside on the same server?<br>
  Should they listen to different ports? Other to port :80 and other to :81 for example?<br>
  Or should I alternatively use sub folders? Going for exampleDomain/app1 and exampleDomain/app2?<br>
  I also read about an option of creating sub domains, but does this work when running my apps in production? </p>
  
  <p>My RoR app is deployed following these instructions:
  <a href="https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04" rel="nofollow">https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04</a>
  (as a note I'm using Digital Ocean's virtual server)</p>
  
  <p>Currently my Nginx file looks the following:</p>
  
  <pre><code>upstream app {
      # Path to Unicorn SOCK file, as defined previously
      server unix:/home/deploy/appname/shared/sockets/unicorn.sock fail_timeout=0;
  }
  
  server {
      listen 80;
      server_name localhost;
  
      root /home/deploy/appname/public;
  
      try_files $uri/index.html $uri @app;
  
      location @app {
          proxy_pass http://app;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect off;
      }
  
      error_page 500 502 503 504 /500.html;
      client_max_body_size 4G;
      keepalive_timeout 10;
  }
  </code></pre>
  
  <p>It's a direct copy from the above RoR tutorial. For some reason if I switch the file name it stops working? Even that I couldn't find the file name being defined anywhere.
  The file is under /etc/nginx/sites-available/ and named "default".</p>
  
  <p>I tried to follow this tutorial for deploying the Nodejs app:
  <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04" rel="nofollow">https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04</a>
  I get my app running with pm2. And I tried writing the following code in another file in /etc/nginx/sites-available/ and also including the code in the existing default file alongside with the code for RoR but neither of them worked.</p>
  
  <pre><code>server {
      listen 80;
  
      server_name example.com;
  
      location / {
          proxy_pass http://APP_PRIVATE_IP_ADDRESS:8080;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
      }
  }
  </code></pre>
  
  <p>Nginx logs are not showing anything useful either. I ran<br>
   <code>sudo tail -f /var/log/nginx/error.log</code> <br>
  a couple of times but the logs were empty.</p>
  
  <p>I would be really thankful if someone could give me some guidance which way to go from here.</p>