Setting up awstats for multiple virtual host logs

I only just realized recently that my apache2 config was outputting logs for my main domain into access.log, and all other virtual hosts into other_vhosts_access.log. As a result, awstats was not picking up hits to the majority of my sites.

To set up awstats to produce stats for each of my stats was relatively easy:

  • Config each virtual host in your apache2.conf to have it’s own CustomLog directive:
    <code><br />
    &lt;VirtualHost *:80&gt;<br />
    ServerAdmin<br />
    DocumentRoot /var/www/html/example<br />
    ServerName<br />
    DirectoryIndex index.jsp index.html<br />
    CustomLog /var/log/apache2/access_example.log combined<br />
    &lt;/VirtualHost&gt;<br />
    <li>Copy your /etc/awstats/awstats.conf to awstats_example.conf – one per each domain where example is the domain name
    <li>Edit each awstats.conf and change the log entry to point to the log file you added in the apache2.conf above, change the DataDir to be /var/awstats/example, and SiteDomain to e.g.
    <li>Create new subdirs for each DataDir in /var/awstats
    <li>Run the stats collection manually to check working:
    sudo /usr/bin/perl /usr/lib/cgi-bin/ -update

  • Update your cron entry to schedule the log processing, e.g. in /etc/cron.d/awstats:
    0,30 * * * * www-data [ -x /usr/lib/cgi-bin/ -a -f /etc/awstats/ -a -r 
    /var/log/apache/access_example.log ] &#038;& /usr/lib/cgi-bin/ -update >/dev/null
  • Add one line for each of the domains you need to collect log stats for. Done!

To access the stats for each of the domains, use the awstats config name passes as a param in the URL:


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.