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 example@example.com<br />
    DocumentRoot /var/www/html/example<br />
    ServerName www.example.com<br />
    DirectoryIndex index.jsp index.html<br />
    CustomLog /var/log/apache2/access_example.log combined<br />
    &lt;/VirtualHost&gt;<br />
    </code></p>
    <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. example.com
    <li>Create new subdirs for each DataDir in /var/awstats
    <li>Run the stats collection manually to check working:
    <pre><code>
    sudo /usr/bin/perl /usr/lib/cgi-bin/awstats.pl -update -config=example.com
    </code>

  • Update your cron entry to schedule the log processing, e.g. in /etc/cron.d/awstats:
    <code>
    0,30 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats_example.com.conf -a -r 
    /var/log/apache/access_example.log ] &#038;& /usr/lib/cgi-bin/awstats.pl -config=example.com -update >/dev/null
    </code>
  • 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:

<code>
http://www.example.com/awstats/awstats.pl?config=example.com
</code>

Leave a Reply

Your email address will not be published.

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