Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My server's name goes like this: When I run the sample node.js application, I can see the hello world message when I go to

I don't want to use the server's host name though.

How can I make node.js run and listen on a different virtual host (like for example or I assume this can be set up in the apache configuration?

share|improve this question
up vote 0 down vote accepted

If apache server isn't listening on port 8124 then I think it doesn't have to do anything with your apache configuration. From node.js docs:

server.listen(port, [hostname], [callback])

Begin accepting connections on the specified port and hostname. If the hostname is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY).

Your sample node.js application have hostname parameter probably omitted, so it's now serving every available hostname under port 8124.

share|improve this answer

In the Node API docs, I think that "hostname" is actually the wrong term. They really mean IP Address. If you use a virtual host name on a server with a single IP address (the typical VPS for example), you will still get responses on both host names.

So setting the hostname on server.listen wont work for you unless you have multiple IP addresses and can assign the sub-domain to one of them.

I think that you have two choices to make this work.

The first would be to restrict Node to only listen on localhost (internal) and use a reverse proxy to handle the incoming request. The proxy would forward the request to the internal node listener. This is not always totally robust as the reverse proxy can be rather picky about static resources such as image files. Additionally, most reverse proxies are "blocking" and so may undo the benefits of using Node. It is also possible to use Node with the http-proxy library to do the proxying.

The second approach is to use some middleware to handle the VHOST. Express is commonly used for this though the capability is actually provided by the Connect middleware library which you could use directly. See:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.