My recent blog about cron reminded me that I’d started this one, but hadn’t got around to finishing it.  I’m using cron in the same jail to run an hourly task to update the web statistic for AWStats that I’d set up in my reverse proxy jail.  I had AWStats set-up and running on my old FEMP jail, which I blogged about here.  It actually makes much more sense for this to happen on my reverse-proxy jail so I can track ALL of the stuff coming into my network.

This blog is just a quick list of steps to add AWStats into a FreeBSD jail that’s already running NGINX:

  • pkg install awstats
  • cd /usr/local/www/awstats/tools
  • ./awstats_configure.pl

This creates the required .conf files in /etc/awstats which you need to edit for your specific installation (update log files, DNS settings, icon location e.g. /awstats/icon,  etc.)

Then create a nginx.conf file

server {
        listen 80;
        server_name awstats.domain.com;
        root /usr/local/www/;                                                                          
        error_log /var/log/nginx/web.error.log;
        access_log off;
        log_not_found off;                                                                             
        location /awstats/classes/ {
                alias /usr/local/www/awstats/classes/;
        }
        location /awstats/css/ {
                alias /usr/local/www/awstats/css/;
        }
        location /awstats/icon/ {
                alias /usr/local/www/awstats/icon/;
        }
        location /awstats/js/ {
                alias /usr/local/www/awstats/js/;
        }
}

To build the stats, and create the HTML files then run:

./awstats.pl -config=awstats.domain.com -update
./awstats_buildstaticpages.pl -config=awstats.domain.com -dir=/usr/local/www/awstats

You should then be able to view the reports at the local IP e.g. http://IP/awstats

awstats screenshot

It’s also possible to integrate GeoIP to give some indication as to the location of visitor tracking

  • pkg install GeoIP
  • pkg install p5-Geo-IP
  • cd /usr/local/bin
  • ./geoipupdate.sh

This creates the GeoIP.dat file in the /usr/local/share/GeoIP folder, which needs to be updated in the awstats.domain.conf file

Finally, adding a cron task to automatically update the AWStats database and HTML files means the information is always kept up to date

  • crontab -e
  • i
  • */60 * * * * /usr/local/www/awstats/tools/awstats_buildstaticpages.pl -config=domain -update -dir=/usr/local/www/awstats
  • esc then :wq

And, depending on how you might expose this across the network, it might be worth adding password access?  Here’s some info on the NGINX website, but it’s simply adding a couple of strings to your location block and then creating a .htpasswd file containing the user credentials.

Now making sense of it all, there’s a whole new challenge 😉