3

Is it possible to have multiple PHP websites and Nodejs App on same VPS?

I have a CentOS VPS with root access on Host Virtual where I'm hosting multiple webistes on LAMP using virtual hosts.. I use port 80 for apache.

Now I want to deploy a nodejs application built on mongoDB and Express framework on same VPS.. I've installed node and express.

  1. I need to know if its a good practice to host node app on same VPS..?
  2. What should I use for routing.. Should I use nginx as front-end proxy for apache and nodejs or can I also use apache for routing my node app url to node app folder..?
casper123
  • 1,736
  • 4
  • 21
  • 39
  • I'd say this is more of an opinion question, but you could use nginx to achieve what you're asking. I would question whether Apache was absolutely necessary and try using nginx as a lightweight handler for all of your proxy rules. You could have the NodeJS server bind to a port other than 80 and have nginx proxy requests to it. Take a look at http://stackoverflow.com/questions/13999069/nginx-nodejs-php – aust Nov 26 '13 at 19:08
  • @aust: Well I'd really like the take opinions from experts :) Its my first time I'm deploying a nodejs App so need to do it very carefully. – casper123 Nov 26 '13 at 19:18

1 Answers1

4
  1. If the server has low load it is ok to combine apache and node.js
  2. You can use nginx or apache mod_proxy to make forwarding to your node.js apps for apache
    <VirtualHost njapp1.domain.com>    
        ProxyRequests Off
        ProxyPreserveHost On

        ProxyPass             /           http://localhost:9000
        ProxyPassReverse      /           http://localhost:9000 
    </VirtualHost>

for nginx

server{
 name njapp1.domain.com;
 location / {
  proxy_pass        http://localhost:9000;
  proxy_set_header  X-Real-IP  $remote_addr;
 }
}
maximus
  • 716
  • 7
  • 18
  • This works great, thanks! I have one small issue though: websockets aren't working. Do you know how I could make this work? – pmalbu Aug 14 '14 at 20:22
  • Here you will find the explanation for websockets also: http://stackoverflow.com/questions/5009324/node-js-nginx-and-now – Nikola Dec 10 '14 at 09:04