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
BUILDING STATS AND ROTATING LOG FILES
sudo /usr/lib/cgi-bin/awstats.pl -config=yourdoamin.com -update
/usr/share/doc/awstats/examples/awstats_updateall.pl now -awstatsprog=/usr/lib/cgi-bin/awstats.pl
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
}