This has always bugged me and I've never got around to figuring out why Apache does this, I always resorted to the mod_vhost plugin to work around the issue.

Basically, I have 2 vhosts in sites-enabled (Ubuntu server), their contents:

<VirtualHost *>
DocumentRoot "/var/www/vhosta.domain.com/"
ServerName vhosta.domain.com
<Directory "/var/www/vhosta.domain.com/">
allow from all
Options +Indexes
</Directory>
</VirtualHost>

And

<VirtualHost *>
DocumentRoot "/var/www/vhostb.domain.com/"
ServerName vhostb.domain.com
<Directory "/var/www/vhostb.domain.com/">
allow from all
Options +Indexes
</Directory>
</VirtualHost>

Now logically these 2 would be accessible separately, however it seems that all requests to my server, no matter what vhosts I define on top of this, are going to vhosta.domain.com.

Am I missing something incredibly obvious? I really don't get why it's doing this..

Thanks

link|improve this question
Where are you defining this vhosts ? In separate files in /etc/apache2/sites-available ? Are you generating the apropiate links in /etc/apache2/sites-enabled ? – Torian Jan 23 at 15:37
feedback

2 Answers

up vote 2 down vote accepted

You are missing a NameVirtualhost; however:

  • DO NOT use VirtualHost *; use VirtualHost *:80 instead.

The following is the correct way:

NameVirtualHost *:80

<VirtualHost *:80>
  Servername vhosta
</VirtualHost>

<VirtualHost *:80>
  Servername vhostb
</VirtualHost>
link|improve this answer
Out of curiosity (and I always used :port myself) - why do you discourage the use of "" ? – spud Jan 23 at 15:41
The apache documentation does. This causes unexpected behaviour when you are listening on more than 1 port. – adaptr Jan 23 at 15:54
Thanks, that was it. I'm surprised webmin does not add this automatically, or Ubuntu for that matter. – Naatan Jan 23 at 15:56
feedback

Before your virtual host definitions, you need something like:

NameVirtualHost *:80

You're doing name-based virtual hosts. See the documentation here:

http://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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