2

In my Ubuntu 16.4 VM I've set up Apache 2.4 successfully and have several vhosts set up. I'm wanting to see server-status but my first vhost keeps preventing that. I've read and re-read the Apache 2.4 docs on this. I've put the following in my /etc/apache2/apache.conf, then in /etc/apache2/mods-enabled/status.conf and finally in the /etc/apache2/sites-enabled/0firstvhost.conf

<Location "/server-status">
      SetHandler server-status
      Require ip 10.211.55.0/24
    </Location>

In reading many posts on this subject in the Apache docs and ServerFault, I've tried many variations that are applicable to Apache 2.4

I can verify mod_status is running by seeing it when running

sudo apachectl -M | grep status

Of course, I've checked the apachectl configtest each time and restarted the apache2 service to see if I can browse to 10.211.55.3/server-status but the Drupal PHP app keeps interfering. There is no .htaccess at the root of this vhost.

I have placed this directive within and without the directive.

I check a browser at the IP addy of the VM and also within the VM run

curl localhost/server-status
curl 10.211.55.3/server-status

The Drupal app gets read first. What to try next? thx, sam

sam452
  • 269
  • 1
  • 6
  • 15

2 Answers2

0

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).
Abdull
  • 187
  • 1
  • 14
0

Found this which suggested the .htaccess for the default site was preventing mod_status from working. Their solution didn't work for me, but since I'm working with virtual hosts anyway I could create a virtual host without an .htaccess. I added an arbitrary host in Debian's /etc/hosts file:

127.0.0.1  foo.org

Created an empty directory among my other virtual hosts and created a new site and enabled it.

<Directory /home/foo.org>
</Directory>
<Location /server-status>
    SetHandler server-status
    Require local
    Require ip 127.0.0.1
    Require ip ::1
</Location>

<VirtualHost *:80>
  ServerAdmin webmaster@mysite.org
  ServerName foo.org
</VirtualHost>

So on localhost I can see the data

curl foo.org/server-status
sam452
  • 269
  • 1
  • 6
  • 15