Awstats + nginx

 

Awstats + nginx 配置手册。

 

 
cd /usr/local/src
wget http://prdownloads.sourceforge.net/awstats/awstats-6.9.tar.gz
tar xzvf awstats-6.9.tar.gz
mv awstats-6.9  ../awstats
cd awstats/tools
./awstats_configure.pl   # 创建一个新的统计
 
++++++++++++++++++++++++++++++++++++++++
Check for web server installEnter full config file path of your Web server.Example: /etc/httpd/httpd.confExample:/usr/local/apache2/conf/httpd.confExample: c:\Program files\apache group\apache\conf\httpd.confConfig file path ('none' to skip web server setup):#> none 
#因为我们这里用的是 Nginx,所以写 none,跳过.
 
Your web server config file(s) could not be found.You will need to setup your web server manually to declare AWStatsscript as a CGI, if you want to build reports dynamically.See AWStats setup documentation (file docs/index.html)-----> Update model configfile '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'  File awstats.model.conf updated.-----> Need to create a new configfile ?Do you want me to build a new AWStats config/profilefile (required if first install) [y/N] ?#> y
#y 创建一个新的统计配置
.
.
.
.
#基本都回车,默认配置文件是保存到(/etc/awstats)
 
 
#接下来修改 xyqfans 的统计配置
 
vi /etc/awstats/awstats.xyqfans.conf
#找到统计的日志文件的路径 LogFile="/var/log/httpd/mylog.log"
#改为
LogFile="/opt/nginx/logs/xyqfans_access_%YYYY-0%MM-0%DD-0.log"
mkdir -p /var/lib/awstats
 
 
#1.然后切割日志:(我们用一个脚步)
 
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
cat nginxlogrotate.sh
#!/bin/sh
#
cd /var/log/nginx
mv xyqfans_access.log /opt/nginx/logs/xyqfans_access_`date +%Y%m%d`.log
kill -s USR1 `cat /usr/local/nginx/logs/nginx.pid`
 
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
mkdir -p /opt/nginx/logs/
./nginxlogrotate.sh
 
 
#2.执行 Awstats 日志更新程序开始统计分析(统计分析的结果放在在 Awstats 的数据库中 /var/lib/awstats)
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=xyqfans
 
 
#3.查看
#在 Apache 上,可以直接打开 Perl 程序的网页查看统计。 但本文开始时已经提到,Nginx 对 Perl 支持并不好,所以我们#要换个方法,利用 awstats 的工具将统计的结果生成静态文件,具体的步骤如下
mkdir /var/www/html/xyqfans/awstats
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=xyqfans -lang=cn -dir=/var/www/html/xyqfans/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
 
 
#上述命令的具体意思如下:
 
/usr/local/awstats/tools/awstats_buildstaticpages.pl Awstats #静态页面生成工具
-update -config=xyqfans #更新配置项
-lang=cn #语言为中文
-dir=/var/www/html/xyqfans/awstats #统计结果输出目录
-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl Awstats #日志更新程序路径。
 
 
#4.nginx 中的配置
vi /usr/local/nginx/conf/nginx.conf
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        server
        {
                listen       80;
                server_name  xyqfans xyqfans;
                index index.html index.htm index.php;
                root  /var/www/html/xyqfans;
 
                if (-d $request_filename)
                {
                        rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
                }
 
                location ~ .*\.php?$
                {
                        include fcgi.conf;
                        #fastcgi_pass  unix:/tmp/php-cgi.sock;
                        fastcgi_pass  127.0.0.1:9000;
                        fastcgi_index index.php;
                }
 
 
 
                location ~ ^/awstats/ {
                       root /var/www/html/xyqfans;
                       index index.html;
                       access_log off;
                       error_log off;
                       charset gb2312;
                }
 
                location ~ ^/icon/ {
                        root /usr/local/awstats/wwwroot;
                        index index.html;
                        access_log off;
                        error_log off;
                        charset gb2312;
                }
 
                log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" $http_x_forwarded_for';
                access_log  /var/log/nginx/xyqfans_access.log  main;
}
 
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
#然后我们来个定时执行: cron
 
vi awstats_analysis.sh >/dev/null 2>&1
 
#!/bin/bash
#1.分割
/usr/local/awstats/nginxlogrotate.sh
 
#2.awstats分析日志并且存放到自己db中
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=xyqfans
 
#3.生成静态页面
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=xyqfans -lang=cn -dir=/var/www/html/xyqfans/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
 
/usr/local/awstats/nginxlogrotate.sh
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=xyqfans
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=xyqfans -lang=cn -dir=/var/www/html/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl

你可能感兴趣的:(nginx,nginx,职场,+,awstats,休闲)