I have installed apache 2 and created and enabled a virtual host.
The virtual host has: ServerName example.com ServerAlias *.example.com ServerAlias foo.com ServerAlias *.foo.com ServerAlias bar.com ServerAlias *.bar.com
If I direct the browser to www.example.com, test.example.com, foo.com, www.foo.com, etc, ANYTHING except the bare server name, it works as expected, showing the content of /srv/www/example.com/public_html/index.php which is the DocumentRoot for the virtual host.
However, if I write only "example.com" in the browser, i see the contents of /var/www/index.html
It's NOT cached in the browser, I have already cleared the cache and also tried another browser and tried through a proxy.
This makes no sense to me. Any idea?
Here are the contents of /etc/apache2/sites-enabled/000-default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And here are the contents of /etc/apache2/sites-enabled/example.com:
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
ServerAlias foo.com
ServerAlias *.foo.com
ServerAlias bar.com
ServerAlias *.bar.com
#... and a few others
DocumentRoot /srv/www/example.com/public_html
ErrorLog /srv/www/example.com/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel notice
CustomLog /srv/www/example.com/access.log combined
<Directory /srv/www/example.com/public_html>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
I can't understand why, with the bare servername, the default vhost prevails over the one that specifically matches the server name, while all aliases work fine.
And here's the output of # apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:443 is a NameVirtualHost
default server example.com (/etc/apache2/sites-enabled/default-ssl:2)
port 443 namevhost example.com (/etc/apache2/sites-enabled/default-ssl:2)
*:80 is a NameVirtualHost
default server example.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost example.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost example.com (/etc/apache2/sites-enabled/example.com:1)
Syntax OK
(I guess it's needless to say that I've replaced the actual domain names with "example.com", "foo.com" and "bar.com" just for posting here at SF)