Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a strange problem with the virtual hosts on my machine.

I have set one up for my domain (let's call it domain1.com) to accept connections on port 80 and its doc root is /var/www/websites/domain1/

Now, that one works when I go to domain1.com, but now if I go to the IP of the machine, instead of going to the default document root (/var/www/) is displays the document root of domain1.com (/var/www/websites/domain1/)

Im running centos5 32bit and apache2

I hope that makes sense :p

share|improve this question
    
Can you show us the apache config? It sounds like the document root of *:80 is also pointing to your domain1 root. –  chunkyb2002 Oct 30 '10 at 19:11
    
I have put it here: pastebin.com/788F2ctG –  Newbzors Oct 30 '10 at 20:01
add comment

1 Answer

IIRC as soon as you enable virtual hosts, the first virtual host takes over the configuration of some of the defaults. For example ServerName and DocumentRoot get overwritten.

Just add another vhost to the beginning of your config and set the same properties as you had before:

<VirtualHost *:80>
    ServerName some.example.com
    DocumentRoot /var/www
</VirtualHost>

<VirtualHost *:80>
...
</VirtualHost>

Edit:

I just had a look at your httpd.conf

as I think you want to use named virtual hosts (multiple host configurations on the same IP) you'll have to explicitly enable

NameVirtualHost *:80

and then the VirtualHost directives should look the same as in my example:

<VirtualHost *:80>
...

if you dont use named vhosts then anything served on a particular IP will come from the same virtual host configuration.

you might also want to have a look at the apache vhost documentation (http://httpd.apache.org/docs/current/vhosts/index.html) to get more familiar with the different concepts of name based vs. IP based vhosts and their respective advantages and drawbacks.

share|improve this answer
    
Thank you, I will give that a go :) –  Newbzors Oct 30 '10 at 20:07
    
Correct, first vhost is the primary/default for the IP/port. –  Rob Olmos Oct 30 '10 at 20:17
    
Thank you for your help, I shall have a look –  Newbzors Oct 30 '10 at 20:44
    
I had a look and tried the suggestions, but it is still sending unhandled requests to domain1.com document root. I am also using webmin if this helps –  Newbzors Oct 30 '10 at 21:15
    
I havent had this problem before when I have setup virtual hosts with webmin, strange :s –  Newbzors Oct 30 '10 at 21:21
show 5 more comments

Your Answer

 
discard

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.