Custom Apache Status page

I spent a good amount of time tweaking the performance of my VPS after learning about several sites hotlinking images from one of my own websites.

Now, this particular tutorial/article won’t be really about Apache performance, rather I’d like to share a little trick I learned for making your Apache server status page more usable.

First, we need to enable our /server-status page. To do this, we’ll need to enable the status Apache module.

a2enmod status

Great, now let’s set up a page that will show our server’s actual status page.

nano /etc/apache2/mods-available/status.conf

According to apache.org, the settings should look something like this:

<Location /server-status>
  SetHandler server-status
  Order Deny,Allow
  Deny from all
  Allow from .example.com
</Location>

If you’re for example running WordPress on the same server, you will also need to exclude this page from the site’s .htaccess file.

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule . /index.php [L]

Save, reload apache –

service apache2 reload

And you’re good to go! Navigate to yourwebsite.com/server-status and you should see something like this:

Out of the box, the server status page doesn’t look like much. And don’t even try to view it on your phone. Luckily, there’s something we can do to improve this.

I came across this article that explains how to use Apache’s substitute module to inject custom CSS – or any other content – to your page.

I also made it so that only certain IP addresses are allowed to view my server status page (feel free to take it a step further and set up a password as well).

My updated status.conf file looks like this.

<Location /server-status>
  SetHandler server-status
  Order deny,allow
  Deny from all
  Allow from IPADDRESS1 IPADDRESS2 IPADRESS3
  AddOutputFilterByType SUBSTITUTE text/html
  SetOutputFilter SUBSTITUTE;DEFLATE
  Substitute 's|</head>|<style type="text/css">@import "/other/server-status/status.css"</style><meta name="viewport" content="width=device-width, initial-scale=1"></head>|'
</Location>

Here is my custom CSS.

And the result:

Being able to inject custom HTML into your server status page gives you quite a lot of freedom, as this person’s Pimped Apache Server Status project shows:

Similarly, you can also customize the looks of your server generated directory listings or your error pages.

More tutorials

A tinted screenshot showing the finished bot posting a flag and asking about a corresponding capital, followed by a reply from me with a correct answer, and the bot accepting it.
A tinted screenshot of profile fields on Mastodon, showing a newly added

Automating your Mastodon profile with Pipedream.com

Show the current time and weather in your city, change your profile picture, or show what you're currently listening to on your Mastodon profile.

#api #automation #mastodon #mastodon-api #mastodon-py #pipedream-com

Screenshot of the finished Mastodon bot posting a protest art image with a raised fist in solidarity.

💻 Browse all