Hosting node.js for a specific domain only on a VPS
Asked Answered
C

3

6

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.

Cockshy answered 3/10, 2011 at 19:43 Comment(2)
Highly recommended to get a separate VPS for this. Use of proxy modules is going to limit features and performance.Feather
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. devcenter.heroku.com/articles/node-jsRelativize
C
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");

Caprifoliaceous answered 3/10, 2011 at 21:37 Comment(6)
Can the host parameter of the listen() method be a domain, e.g. server.listen(80, "example.com")?Fijian
Thanks BRO!! saved my arse .. question!! How does this work .. how can i be listening to port 80 with apache and nodejs???Paradies
@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.Caprifoliaceous
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.Paradies
@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 :)Caprifoliaceous
@Caprifoliaceous 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.Paradies
H
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.

Helpless answered 3/10, 2011 at 19:48 Comment(0)
T
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.

Toulouselautrec answered 3/10, 2011 at 20:2 Comment(2)
I've edited the question. Won't having a separate IP eliminate the use of proxies?Cockshy
You can have apache listen on the one IP and node.js on the other IP and they won't interfere each other.String

© 2022 - 2024 — McMap. All rights reserved.