AWstats statistics with sub domains on lighttpd

One of the best tools to analyse web visits is AWstats. This tool gives very detailed information about the visitors on your web site. It will analyse the log file of the web server, and turns this into very nice statistics. In the default configuration, it has only limited support for lighttpd. You can set the log type to Apache, and you will get some kind of logging. However, this lumps all sites into one. If you have sub domains, some tweaking is needed to get separate statistics for each sub domain.

I installed AWstats using the Debian package manager. This will install the configuration files in /etc/awstats There are two files there: awstats.conf contains basic settings, awstats.conf.local is imported by awstats.conf and can be used to overwrite certain settings.

For each of the sub domains, a separate configuration file is needed. It needs to be in a specific format: awstats.sub.domain.net.conf For example, the config file for this site would be awstats.server.vijge.net.conf The awstats.conf file will gather statistics for all sub domain together, and the awstats.conf.local file will contain all the general settings.

First, delete the current awstats.conf.local file, and copy the current awstats.conf file to awstats.conf.local Next, make some changes the the awstats.conf.local file:
1. Change the LogFile variable to point to the lighttpd log file. In the default Debian configuration, this would be LogFile="/var/log/lighttpd/access.log"
2. Change the LogFormat to the log settings for lighttpd. LogFormat="%host %virtualname %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"
3. Place a comment character (#) before SiteDomain and HostAlias #SiteDomain=""
#HostAliases=""

4. At the end of the file, there is an include of the awstats.conf.local file. But because this is already the awstats.conf.local file, the include has the be removed, to make sure there is no infinite include loop.
#Include "/etc/awstats/awstats.conf.local"

That is it for the generate configuration. Now configure the configuration for each sub domain, and for the total site. Open the file awstats.conf, and replace all contents by
SiteDomain="domain.net"
HostAliases="localhost 127.0.0.1 REGEX[domain\.net$]"

Include "/etc/awstats/awstats.conf.local"

Add your domain name in the regex expression, so all domains are matched. For each sub domain you want to track, make a new file with the name awstats.sub.domain.net.conf and place the following code it in
SiteDomain="sub.domain.net"
HostAliases="sub.domain.net"

Include "/etc/awstats/awstats.conf.local"

The configuration is now done. Now you need to make sure your web server knows about AWstats. First, create a separate directory in your www folder (e.g. /var/www/awstats). In this directory, make a symbolic link to the awstats executable: ln -s /usr/lib/cgi-bin/awstats.pl Edit the file /etc.lighttpd/lighttpd.conf to include

alias.url += ( "/awstats-icon" => "/usr/share/awstats/icon" )
alias.url += ( "/awstats" => "/var/www/awstats" )
$HTTP["url"] =~ "^/awstats($|/)" {
cgi.assign = (
".pl" => "/usr/bin/perl",
".cgi" => "/usr/bin/perl"
)
}

If you visit the AWstats page, it will display the statistics for the current sub domain. If you view AWstats from the domain server.vijge.net, the statistics for that domain are displayed. To change to a different domain, simply place an argument behind the url, e.g. awstats.pl?config=daniel.vijge.net The part behind the config= corresponds to the name given to each config file, between awstats and .conf To view the statistics for all the domains (as configured in awstats.conf), supply an invalid config parameter, e.g. awstats.pl?config=all
I created a simple page with links to the statistics for each sub domain, to I can easily browse to them.

If you installed AWstats under Debian Squeeze, it runs as a cron job, so all the statistics are updated every 10 minutes. Under older versions of Debian this script is not included, but you can download it here. Save this as /usr/share/awstats/tools/update.sh, make is executable, and change the file /etc/cron.d/awstats to read
*/10 * * * * www-data [ -x /usr/share/awstats/tools/update.sh ] && /usr/share/awstats/tools/update.sh

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.