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..?
2
  • 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 Commented Nov 26, 2013 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. Commented Nov 26, 2013 at 19:18

1 Answer 1

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;
 }
}
Sign up to request clarification or add additional context in comments.

2 Comments

This works great, thanks! I have one small issue though: websockets aren't working. Do you know how I could make this work?
Here you will find the explanation for websockets also: stackoverflow.com/questions/5009324/node-js-nginx-and-now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.