Setting up AWstats to parse Nginx log files served from Apache
After moving most of my Ruby apps onto Apache I got back to the idea of wanting to do my own log analysis. Although the Google analytics urchin is nice, I prefer something more unobtrusive. I have used AWstats in the past, and was always quite impressed with its feature set. After installing Apache again, I figured I would give it a go. I prefer using the packaged AWstats because that way it will (hopefully) automatically update through apt. This post on AWstats by Sami Dalouche was really helpful in getting my head around the packaged AWstats configuration on Debian. This will show you how to make awstats virtualhosts for every domain on your site, show you how to set up a cronjob and prevent logrotate from rotating the logs before AWstats has run. So after you have copied a new awstats.<yourvhost>.conf file in /etc/awstats/, set up the following variables: (This of course implies you have set the access_log to the same location, /var/log/nginx/<yourvhost>-access.log)
LogFile=”/var/log/nginx/<yourvhost>-access.log” SiteDomain=”<yourvhost>” HostAliases=”<yourvhost>” DirData=”/var/lib/awstats/<yourvhost>”
And set the logformat for Nginx:
LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"
Now for the Apache Virtualhost, which is also largely boilerplate.
<VirtualHost>
ServerName <yourvhost>
Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon/ "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /stats /usr/lib/cgi-bin/awstats.pl
# This is the important bit. It tells AWstats to use your defined vhost config from the .conf file, rather than try to parse the Apache log.
SetEnv AWSTATS_FORCE_CONFIG <yourvhost>
</VirtualHost>
If the website you want to monitor is already being served from Apache, and Nginx proxies requests for nonexistent files to Apache you are probably done. Go check <yourvhost>/stats/!
If the site is served using only Nginx (static assets) you will have to add a proxy_pass in your Nginx virtualhost for the 4 paths in the VirtualHost definition needed by awstats.
Hope this helps people out who are struggling to get this set up! It took me about a day in total, I think. Now I have fancy separate stats on all my public Nginx websites!
Trackbacks
Use the following link to trackback from your own site:
http://blog.aczid.nl/trackbacks?article_id=24










