How can you view the current state of the Apache web server? How much memory is it using right now? What percentage of CPU time is it consuming? What connections does it have at the moment and what is each connection doing? These are the questions answered by the module that ships with Apache called "mod_status".
In this note I'll explain how to set up mod_status on a Linux Debian server.
Enabling and configuring1) Go to the /etc/apache2/mods-available directory
2) Open the status.conf file for editing
3) In it we see the mod_status settings. We need to tweak a few of them, since by default only users connecting from the server itself (127.0.0.1) have access
To allow the status page to be accessed from other IP addresses, add after the line
Allow from 127.0.0.1
more lines like this
Allow from 192.168.0.1
where you specify the IP addresses that can access the status page.
4) Enable the module itself.
To do this, create a symlink to its files in the mods-enabled directory:
$ sudo ln -s /etc/apache2/mods-available/status.load /etc/apache2/mods-enabled/status.load
$ sudo ln -s /etc/apache2/mods-available/status.conf /etc/apache2/mods-enabled/status.conf
5) Restart Apache
$ sudo /etc/init.d/apache2 restart
6) Go to the status page:
http://192.168.0.1/server-statuswhere instead of 192.168.0.1 enter the IP address of your web server (the one on which we're currently setting up mod_status).
A page should open with information about the current state of the Apache server.
Restricting access to the page by passwordHowever, it's not always possible, and simply not always good practice, to restrict access only by IP. For example, from a single address there could be people who are allowed and people who aren't (for instance, sitting behind NAT).
Let's restrict access by login and password. For this we'll use the htpasswd technique.
First let's create a file in the .htpasswd format. Let's call it status.passwd:
$ cd /etc/apache2/
$ sudo htpasswd -c status.passwd adminuser
where instead of adminuser specify the login of the user who will be able to access this page. After that, enter a password for this user at the utility's prompt.
Other users can be added the same way, only the -c flag must not be specified:
$ sudo htpasswd status.passwd anotheruser
Now open the status.conf file again for editing and bring the <Location> section to this form:
<Location /server-status>
SetHandler server-status
Order allow,deny
Allow from all
AuthName "Enter password for access"
AuthType Basic
AuthUserFile /etc/apache2/status.passwd
require valid-user
</Location>
And restart the web server:
$ sudo /etc/init.d/apache2 restart
And that's it — the next time you visit the status page, you'll be asked for a login and password.
Applies to: Debian 5 (Lenny), 6 (Squeeze); Apache 2.x
Comments