Navigation: home » linux » apache-default-pages

Default Pages For Apache vhosts

When using name based virtual hosting with Apache, the first site for an IP address is used if no other virtualhost matches. For example, if the IP 10.11.12.13 hosts example.com and example.net but somebody browses to example.org, the first site for 10.11.12.13 will be returned. The same will also happen if somebody browses to 10.11.12.13.

This isn’t ideal in a mass virtual hosting scenario, so a simple solution is needed. As we know that the first vhost is always used, we can simply include a default site for each IP. However, one cavaet to watch out for is that results can be unpredictable if there is no ServerName for this vhost, so to get round this it is useful to use the IP itself.

# Default vhost
NameVirtualHost 10.11.12.13:80

<VirtualHost 10.11.12.13:80>
  ServerName 10.11.12.13
  DocumentRoot /var/www/default/htdocs
  ServerAdmin admin@isp.example.com
</VirtualHost>

<VirtualHost 10.11.12.13:80>
  ServerName example.net
  DocumentRoot ..
  CustomLog ..
  ErrorLog ..
  ServerAdmin admin@example.net
</VirtualHost>

The results of this can be seen by browsing to http://80.249.110.200, the IP that this site is currently served from.