5

I have a VPS where I have hosted a few sites. All based on LAMP stack, so it was no big deal. They provide WHM/cpanel for managing different sites. I decided to try node.js, bought a separate domain for it, and I need some clue how to point that domain to the node.js application.

So here are the questions:

1) What is the best way to host node.js application on a specific domain without hampering the other sites? How will I configure the domain? Yes, I'd like to use default http port (80) for node.

2) As Apache is already listening to the 80 port, is it a good idea to use Apache mod_proxy for the purpose? I mean if I want to use websocket, will apache still use separate threads for maintaining connection to node?

PS. I have already seen this question, but the answers don't seem to be convincing.


Edit:

I forgot to mention, I have an unused dedicated IP for that VPS which I can use for node.js.

Community
  • 1
  • 1
Mehdi
  • 1,075
  • 1
  • 11
  • 24
  • 1
    Highly recommended to get a separate VPS for this. Use of proxy modules is going to limit features and performance. – Fosco Oct 03 '11 at 19:56
  • 1
    You can get up and running with a node app fairly quickly on Heroku and point your domain to the Heroku app instance and not have to bother with Apache proxies. http://devcenter.heroku.com/articles/node-js – mhoofman Oct 03 '11 at 20:02

3 Answers3

9

Follow these steps

  1. Goto "WHM >> Service Configuration >> Apache Configuration >> Reserved IPs Editor" and then 'Reserved' the IP that you want to use for node.js. This will release the IP from apache.

  2. Create a new DNS entry with a A entry like - example.com A YOUR_IP_ADDRESS

  3. Tell the node.js server to listen to your IP using server.listen(80, "YOUR_IP_ADDRESS");

Rifat
  • 7,628
  • 4
  • 32
  • 46
  • Can the host parameter of the listen() method be a domain, e.g. `server.listen(80, "example.com")`? – snapfractalpop Sep 20 '12 at 01:44
  • Thanks BRO!! saved my arse .. question!! How does this work .. how can i be listening to port 80 with apache and nodejs??? – Ray Garner Apr 29 '13 at 06:23
  • @RayGarner, no In step 1 you are releasing the IP from Apache. Apache and NodeJS, both can not run in the same port. This example was given for VPS with multiple IPs. Initially they are reserved by apache even if you are not using them. So, using this way you can free an IP for using with NodeJS. – Rifat Apr 30 '13 at 13:29
  • Yes I see but doesnt a VPS only have one port 80. Thats what I dont get... why can this be done on a vps with multiple ips but not say on my machine at home. Doesnt a box/virtualbox only have one port 80. Even if its released from apache shouldnt that port still be use by apache serving other ips. Im a programmer not a sys admin so just curious. Also this method worked like a charm just was curious why this is possible. Thanks for the answer saved my day. – Ray Garner Apr 30 '13 at 14:42
  • @RayGarner, don't worry I'm a programmer too :) And, you can use same port several times using different IPs. Give it a try in your local machine :) – Rifat Apr 30 '13 at 15:11
  • @Rifat Thanks well I just got tooken to school ;) So now I know that ports are specific to an IP and NOT a machine. For some reason I had a image in my head with a machine being only assigned so many ports. But ports are assigned by IP on the physical device. Not to the device itself. Clear as day now. Thanks. – Ray Garner May 01 '13 at 00:50
0

If Apache is already listening to port 80, then the only thing you can do is proxy to your node instance. And yes, apache will create a new thread for each connection.

swatkins
  • 13,530
  • 4
  • 46
  • 78
0

As others have mentioned, there's not a whole lot you can do here. Apache is currently driving your server and node.js won't like riding shotgun.

I'd recommend checking out things like nodester, no.de, heroku, and so on.

Community
  • 1
  • 1
Chance
  • 11,043
  • 8
  • 61
  • 84
  • I've edited the question. Won't having a separate IP eliminate the use of proxies? – Mehdi Oct 03 '11 at 20:05
  • You can have apache listen on the one IP and node.js on the other IP and they won't interfere each other. – Eliasdx Oct 03 '11 at 20:16