Variable Web Content
I’ve been knee-deep in server administration the past couple days, mostly Apache-related. I did some trickery with AWStats page statistics files, VirtualHosts, and mod_rewrite, and thought I would share.
My Apache virtual hosts live in directories in /var/www, each named with their full domain name. Blogs live in /var/www/blogs.bwerp.net/, and so on. Each /var/www/<domain> directory contains at minimum an htdocs and logs directory, so web files and their corresponding logs are segmented from the other domains.
I wanted to run AWStats on all these log files, and my first reaction was to create /var/www/<domain>/stats for each domain I wanted to analyze. This meant my number of tasks was high:
- Create the
statsdirectory for each domain. - Point the
awstats_buildstaticpages.plscript to the correct destination directory. - Create an Apache Alias directive for each domain with stats, or suffer through a
statsdirectory in eachhtdocsfolder.
My final solution was much more elegant than what I originally considered. AWStats creates static pages in the format awstats.<domain>.<type>.html, so each file implicitly “knows” what domain it refers to. I created /var/www/awstats-pages to hold the static pages for every domain. Next, I created a global Alias that is applied to each VirtualHost:
#
# awstats generated pages
#
Alias /stats /var/www/awstats-pages
<Directory /var/www/awstats-pages>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/stats/$
RewriteRule ^(.*)$ /stats/awstats.%{SERVER_NAME}.html
</Directory>
When a user requests http://<domain>/stats/, they are transparently redirected to awstats.<domain>.html in the same directory. The links on each page already go to subpages for the domain, so no other work is necessary. One Alias, one stats directory, infinite domains, less changes in my scripts and the httpd.conf file, and transparency for the user. All good things.
So when do I get my own graffiti board? d:
Eh, someday.
My goodness, all that jibba-jabba’s the reason I got out of the computer buisiness. I pitty the foo that understands all that…
Stumbed on this thanks to Google… very anxious to try it out. Many thanks for the tip in advance
Hi! Great solution! How do you secure the access and how do you manage the different months?
Gerd,
I’m using your run-of-the-mill AuthType Digest to limit access. As for managing the different months, currently I’m not doing that. I don’t know AWStats inside and out, but AFAIK the static pages are only generated for the current month. I imagine a similar setup is possible using the AWStats CGI, but I’ve not yet been motivated enough to set it up.