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've got a standard build of RHEL6 and I used to be able to browse to the server's DocumentRoot using the IP address.

I've since added these two vhosts (just the top section is shown). For some reason, now when I access the server's IP address, the Vhost answers and the wrong DocumentRoot is used.

I don't really want to explicitly define a Vhost for /var/www/html.

Another note... I have added NameVirtualHost *:80 to httpd.conf.

Any ideas why the vhosts are answering this?

==> axxx-http.conf <==

<VirtualHost *:80>
ServerAdmin beren@xxyy.com
ServerName xxyy.com
ServerAlias www.xxyy.com
DocumentRoot /var/www/site
<Directory /var/www/site>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all

==> axxx-ssl.conf <==

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName xxyy.com
    ServerAlias www.xxyy.com
    ServerAlias admin.xxyy.com
DocumentRoot /var/www/site
<Directory /var/www/site>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
share|improve this question

2 Answers 2

up vote 4 down vote accepted

When you start to use virtual hosts on a webserver you have to make a virtual host for the normal server too. If you don't create one, the first virtual host defined will be the default one for any connections to the server not matched by another virtual host ServerName or ServerAlias directive.

Check the section "Main host goes away" on this URL for this explanation:
http://httpd.apache.org/docs/2.2/vhosts/name-based.html

share|improve this answer
    
Appreciate the help. Cheers! –  Samuurai Feb 10 '12 at 16:42

The *:80 tells that vhost to answer on port 80 for every IP. If you are going to do Name Based Virtual Hosts, you must define a default as default:80 with what you want for the default. You cannot use both vhost and non-vhost configs on the same port.

share|improve this answer
    
I believe its actually _default_:80 if you chose to use this method instead of the one I suggested above (first virtual host directive being automatically the default one). –  Mattias Ahnberg Jan 21 '12 at 2:04
    
@MattiasAhnberg Actually, if it's specified like that it'll not match the NameVirtualHost directive (assuming it's not set to NameVirtualHost _default_:80) - that configuration would be inert. The first to load that matches will always be the default. –  Shane Madden Jan 21 '12 at 9:27
    
@ShaneMadden If you check my answer above my suggestion is to define the first virtual host as the default one. But you're supposed to define NameVirtualHost as *:80 then create a _default_:80 for the default virtual host. Check apache documentation: httpd.apache.org/docs/2.0/vhosts/examples.html#default –  Mattias Ahnberg Jan 21 '12 at 15:21
    
@MattiasAhnberg Indeed - What I am saying that your answer is the only valid one, and that _default_ doesn't work. It's only for, quoting from the page you linked, "an address/port combination that is not used for any other virtual host.", which isn't true of an address/port combination that has several vhosts on the ip/port combo (as you would in a name-based vhosts setup). –  Shane Madden Jan 21 '12 at 20:42

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.