Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I have a server with IP address

I want to setup virtual hosting such that:

( is already pointing to in dns server)

share|improve this question

The "default host" should be your doc-root A. Then add name based virtual hosts for B and any additional domains.

In your main config file default configurations including DocumentRoot should be setup for hosting site A. Also you should have a line such as NameVirtualHost *:80 to setup virtual hosting for everything on port 80. Then in your virtual host file you will have something like this for each domain:

<VirtualHost *:80>
    DocumentRoot /path/to/B

Anything without a virtual host and matching server name will use the default host, with your docroot set to A.

share|improve this answer
i have added a name based virtual host. the problem now seem that since the IP and the domain are pointing to the same machine using same port, when i type the domain, the browser lead me to DocRoot A which is the same as the ip address – Yang Zheng Apr 13 '11 at 11:06
Yang it is possible to host different sites for the IP address when called directly and various domains that point to the same IP address. Your problem is your configs ... if you have the default setup correctly to catch unknown names, this will catch the IP address-as-name senario as well. It sounds like your virtualhost is not being recognized at all. – Caleb Apr 13 '11 at 11:15
what are the setting i need to mod? i mean the 'default setup' catching unknown names. – Yang Zheng Apr 13 '11 at 11:30
i do have the NameVirtualHost *.80 specified in ports.conf file. and the virtual host file is very similar to yours (only diff are mine have ServerAlias option specified). I use the -S option to check the syntax of the vhost file, it says OK. – Yang Zheng Apr 13 '11 at 11:33
The most relevant settings are in my answer already, including haveing a DocumentRoot directive in the common config file outside of any VirtualHost container. If you are still having trouble it might be helpful to post your current configs to or some such place so we can look at them. – Caleb Apr 13 '11 at 11:37

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.