dotdotdot

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:

  1. Create the stats directory for each domain.
  2. Point the awstats_buildstaticpages.pl script to the correct destination directory.
  3. Create an Apache Alias directive for each domain with stats, or suffer through a stats directory in each htdocs folder.

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.

6 Responses to “Variable Web Content”

  1. Karl

    So when do I get my own graffiti board? d:

  2. Adam Backstrom

    Eh, someday. ;)

  3. Mr. T (But really Craig)

    My goodness, all that jibba-jabba’s the reason I got out of the computer buisiness. I pitty the foo that understands all that…

  4. Thaddeus

    Stumbed on this thanks to Google… very anxious to try it out. Many thanks for the tip in advance :)

  5. Gerd

    Hi! Great solution! How do you secure the access and how do you manage the different months?

  6. Adam Backstrom

    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.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>