[Koha] Koha and Apache NameVirtualHost confusion

Kevin O'Rourke lists at caboose.org.uk
Mon Mar 5 22:00:07 NZDT 2007

As often happens, writing an email describing the problem has helped me 
to find the solution.  I'll reply to my question here for the benefit of 
anyone who has the problem in future.

It's all related to how Apache resolves virtual hosts, they have a very 
long document describing how it works at 

The tricky part is that your default server, which on Debian is probably 
specified in /etc/apache2/sites-available/default is only the default if 
NO virtual hosts were matched.  If Apache finds a vhost/namevhost match 
for the IP address that will override the _default_ namevhost even if 
the name is not correct!

In my case, somebody tries to access mail.nti.gov.ng:
- the IP address is
- Apache looks that address up in its hash of vhost IP addresses and 
finds it
- that IP address has one virtual host listed, opac.nti.gov.ng
- opac.nti.gov.ng doesn't match the requested URL but it's the default 
FOR THAT IP ADDRESS (because it's the only vhost for that IP)
- Apache serves up opac.nti.gov.ng instead of what we really wanted

The _default_ vhost is only used if Apache receives a request for an IP 
address that is not mentioned in any vhost/namevhosts.

To fix the problem I had to alter /etc/apache2/sites-available/default 
so that the VirtualHost line is:
    <VirtualHost _default_:80 mail.nti.gov.ng:80 mail.ntilan:80>

This means that for IP address both opac.nti.gov.ng AND 
mail.nti.gov.ng are listed.  The entry for mail.nti.gov.ng will be read 
first, in /etc/apache2/sites-enabled it's in 000-default which comes 
before 010-koha, so it is the default.

I hope this helps somebody else as the way it works seems fairly 
counter-intuitive to me.  The horrible interactions between different 
vhosts also makes Debian's efforts to keep config files separate a 
little pointless.


More information about the Koha mailing list