AWStats – Nginx

 

AWStats is by default tuned to work with the Apache log, in this article I will show how to get statistics from Nginx logs.

Install Awstats and the GeoIP module

yum install awstats htmldoc GeoIP perl-Geo-IP

Install the Perl handler

yum -y install spawn-fcgi fcgi-devel wget
yum -y groupinstall "Development Tools"
mkdir /tmp/perl && cd /tmp/perl && wget http://github.com/gnosek/fcgiwrap/tarball/master -O fcgiwrap.tar.gz
tar -xf fcgiwrap.tar.gz && cd gnosek-fcgiwrap-*

autoreconf -i
./configure
make
make install

Add launch options to the config:

vim /etc/sysconfig/spawn-fcgi
OPTIONS="-u nginx -g nginx -a 127.0.0.1 -p 9001 -P /var/run/spawn-fcgi.pid -- /usr/local/sbin/fcgiwrap"

Ставим в автозагрузку и включаем:

systemctl enable spawn-fcgi
systemctl start spawn-fcgi

We bring the access log of Nginx to the following form:

vim /etc/nginx/nginx.conf
log_format stats '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';

We re-read the configuration of Nginx.

Create an AWStats configuration file for a specific site:

vim /etc/awstats/awstats.artem.services.conf
LogFile="/var/log/nginx/access.log"
LogFormat=1
SiteDomain="artem.services"
HostAliases="localhost"
DNSLookup=0
DirData="/var/lib/awstats/artem.services"
AllowToUpdateStatsFromBrowser=1
LoadPlugin="geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat"
Lang="ru"

Copy the AWStats script to the web directory, where we will go to see the statistics:

cp -a /usr/share/awstats/wwwroot/cgi-bin/* /home/artem/web/awstats/

Let’s create Nginx config for AWStats:

server {
    listen 80;
    server_name artem.services;
    root /home/artem/web/awstats;

    location / {
        rewrite ^ http://artem.services/awstats.pl?config=artem.services;
    }

    location /icon/ {
        alias /usr/share/awstats/wwwroot/icon/;
    }

    location /css/ {
        alias /usr/share/awstats/wwwroot/css/;
    }

    location /js/ {
        alias /usr/share/awstats/wwwroot/js/;
    }

    location ~ \.pl$ {
        access_log off;
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  awstats.pl;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        /etc/nginx/fastcgi_params;
    }
}

My statistics were filled in through the script and the instructions of the config, but without specifying the domain name in the file name, and through the browser everything is ok and the statistics are updated, so the following went into my crown:

wget -O /dev/null http://artem.services/awstats/awstats.pl?framename=mainright\&update=1

Tagged: Tags

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments