Monitoring our web server is something we need to do regularly. The usage statistics allow us to identify bottlenecks and to manage the necesary resources properly.

Apache Server 2 has a module which shows us this information in real time. It usually comes installed by default and we simply need to toggle it on. To do this we head to the server’s config folder:
sudo nano /etc/apache2/apache2.conf
and remove the comment on the line
ExtendedStatus on
add the lines
<Location /server-status>
  SetHandler server-status
  AuthType basic
  AuthName "Apache Server Status"
  AuthBasicProvider file
  AuthUserFile /etc/apache2/.htpasswd
  Require valid-user
</Location>

We’ll see the server status by accessing page/server-status, where we’ll be asked for a username and password. To sign up, we first download the apache2-utils package if we haven’t already:

sudo apt-get update
sudo apt-get install apache2-utils

Use the command htpasswd to create the file with authorized users:
sudo htpasswd -c /etc/apache2/.htpasswd xxxx

where xxxxx is the username. We now require a password for the user. We can add additional users with the same command without -c. Once the username and password have been entered correctly, we’ll be able to see the server statistics:

Let’s display this information in a more visually attractive way. To do so we’ll use the mod_lua module, which extends the functionalities of our server. We enable it the same way as always: sudo a2enmod lua and download the script server-status.lua. Now add to our apache2.conf the line AddHandler lua-script .lua, upload the server-status.lua script to our server and change the directive location to:
<Files "server-status.lua">
  AuthType basic
  AuthName "Apache Server Status"
  AuthBasicProvider file
  AuthUserFile /etc/apache2/.htpasswd
  Require valid-user
</Files>

We can also add  /Redirect "/server-status/" "ubicacion/de/server-status.lua" to our .htaccess  if we want to keep logging in like before. If everything went well we should see something like this:

A much more comprehensible result.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments