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.

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

share|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 '12 at 15:37
add comment

2 Answers 2

up vote 3 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>
share|improve this answer
    
Out of curiosity (and I always used :port myself) - why do you discourage the use of "" ? –  clmssz Jan 23 '12 at 15:41
    
The apache documentation does. This causes unexpected behaviour when you are listening on more than 1 port. –  adaptr Jan 23 '12 at 15:54
    
Thanks, that was it. I'm surprised webmin does not add this automatically, or Ubuntu for that matter. –  Naatan Jan 23 '12 at 15:56
add comment

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

share|improve this answer
add comment

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.