awstats installation

Set Up AWStats for Nginx on Ubuntu

sudo apt-get install awstats

add access log file to generate stats using this

server {
# ... all your other config ...
access_log /var/log/nginx/yourdomain.com.access.log;
# ... all your other config ...
}

/etc/nginx/sites-available

vi awstats.parleproducts.com.conf

cd /etc/awstats/

vi awstats.parleproducts.com.conf

#path to your nginx log file
LogFile=”/var/log/nginx/parleproducts.com.access.log”

# Domain of your vhost
SiteDomain=”parleproducts.com”

# Directory where to store the awstats data
DirData=”/var/lib/awstats/”

# Other domains/subdomain you want included from your logs, for example the www subdomain
HostAliases=”www.parleproducts.com”

# If you customized your log format above add this line:

LogFormat = “”%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot””

# If you did not, uncomment and use this line:
# LogFormat = 1

sudo /usr/lib/cgi-bin/awstats.pl -config=parleproducts.com -update

Generate the website from below link

sudo /usr/lib/cgi-bin/awstats.pl -config=parleproducts.com -output -staticlink > /var/www/html/awstats/index.html

Now add awstats folder in the location of root folder of that domain

cd / usr / local
wget http://prdownloads.sourceforge.net/awstats/awstats-7.2.zip
unzip awstats-7.2.zip
mv awstats-7.2 awstats

BUILDING STATS AND ROTATING LOG FILES

Now that we have our log files, and we’ve told AWStats where they are, what format they’re in and where to put its analysis, it’s time to actually run AWStats and get the raw data analyzed. To do that we use this command:
sudo /usr/lib/cgi-bin/awstats.pl -config=yourdoamin.com -update
Alternately, if you have a bunch of config files you’d like to update all at once, you can use this wrapper script conveniently located in a completely different directory:
/usr/share/doc/awstats/examples/awstats_updateall.pl now -awstatsprog=/usr/lib/cgi-bin/awstats.pl
You’re going to need to run that command regularly to update the AWStats data. One way to do is with a crontab entry, but there are better ways to do this. Instead of cron we can hook into logrotate, which rotates Nginx’s log files periodically anyway and conveniently includes a prerotate directive that we can use to execute some code. Technically logrotate runs via /etc/cron.daily under the hood, so we haven’t really escaped cron, but it’s not a crontab we need to keep track of anyway.
Open up the file `/etc/logrotate.d/nginx` and replace it with this: 

/var/log/nginx/*.log{
daily
missingok
rotate 30
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
prerotate
/usr/share/doc/awstats/examples/awstats_updateall.pl now -awstatsprog=/usr/lib/cgi-bin/awstats.pl
if [ -d /etc/logrotate.d/httpd-prerotate ]; then
run-parts /etc/logrotate.d/httpd-prerotate;
fi
endscript
postrotate
invoke-rc.d nginx rotate >/dev/null 2>&1
endscript
}
The main things we’ve changed here are the frequency, moving from weekly to daily rotation in line 2, keeping 30 days worth of logs in line 4, and then calling AWStats in line 11.

One thing to bear in mind is that if you re-install Nginx for some reason this file will be overwritten.

Leave a Comment

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

Open chat