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 CentOS or Red Hat server.
Configuration1) Go to the /etc/httpd/conf directory
2) Open the httpd.conf file for editing
3) In this file find the "ExtendedStatus On" option and uncomment it if we need additional information on the status page.
4) Now find the "<Location /server-status>" block. It is commented out initially, so the first thing we need to do with it is uncomment it.
5) Initially the module is configured so that it doesn't let anyone in at all — there is only a "Deny from all" line, but no "Allow..." lines. So after the "Deny from all" line, add lines like these:
Allow from 192.168.0.1
Allow from 192.168.0.2
With this we tell the module which IP addresses to allow access from.
6) Close the file and restart the web server:
$ sudo /etc/init.d/httpd restart
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/httpd/conf/
$ 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 httpd.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/httpd/conf/status.passwd
require valid-user
</Location>
And restart the web server:
$ sudo /etc/init.d/httpd restart
And that's it — the next time you visit the status page, you'll be asked for a login and password.
Applies to: CentOS 5/6 or RedHat 5/6; Apache 2.x
Comments