3
votes

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..?
1
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 stackoverflow.com/questions/13999069/nginx-nodejs-php - aust
@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

1 Answers

4
votes
  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;
 }
}