I also had the problem of my VirtualHost /etc/sites-enabled/example.conf
handling requests for http://localhost/server-info, which I actually wanted to be handled by mod_info.
# File /etc/sites-enabled/example.conf
<VirtualHost *:80>
ServerName example.com
# ...
</VirtualHost>
The problem was IMHO that Apache has a default fallback request handling behavior if some request does not match any configured VirtualHost's ServerName (see 1, 2). As mod_info's default configuration files /etc/apache2/mods-available/info.load
and /etc/apache2/mods-available/info.conf
don't specify their own VirtualHost and ServerName, I guess Apache's fallback kicked in, having my example.conf VirtualHost handle the request for http://localhost/server-info.
I fixed the problem the following way:
Create a file /etc/apache2/mods-available/localhost-server-info.load
(notice mods-available
). This is a copy of the original info.load
:
LoadModule info_module /usr/lib/apache2/modules/mod_info.so
Create a file /etc/apache2/sites-available/localhost-server-info.conf
(notice sites-available
). This is an adaption of the original info.conf
, wrapping its content inside a VirtualHost and providing a ServerName:
# Get mod_info information by requesting http://localhost/server-info
#
# Enable by executing
# service apache2 stop
# a2dismod info
# a2enmod localhost-server-info
# a2ensite localhost-server-info
# service apache2 start
#
# Disable by executing
# service apache2 stop
# a2dissite localhost-server-info
# a2dismod localhost-server-info
# service apache2 start
<IfModule mod_info.c>
<VirtualHost *:80>
# Adapt ServerName to your needs
# Avoid ServerName collision with any other active VirtualHosts
ServerName localhost
<Location /server-info>
SetHandler server-info
# Adapt Require to your needs
# Require local
# Require ip 192.0.2.0/24
</Location>
</virtualHost>
</IfModule>
Disable the original info module (in case it is still enabled) and enable the new localhost-server-info module and site:
service apache2 stop
a2dismod info
a2enmod localhost-server-info
a2ensite localhost-server-info
service apache2 start
- http://example.com/server-info should now be handled by the example.com VirtualHost (probably showing a 404 page).
- http://localhost/server-info should now be handled by mod_info.
- http://127.0.0.1/server-info and other non-configured ServerNames should be handled according to Apache's fallback handling, e.g. in my example by the example.com VirtualHost (probably showing a 404 page).