使用awstats分析nginx日志

date:星期六, 十一月 14th, 2009 at 10:08 下午 Categories:linux

awstats 是一个很方便的日志分析工具
空间商提供了之后自己尝试装下

  • 访问次数、独特访客人数,
  • 访问时间和上次访问,
  • 使用者认证、最近认证的访问,
  • 每周的高峰时间(页数,点击率,每小时和一周的千字节),
  • 域名/国家的主机访客(页数,点击率,字节,269域名/国家检测, geoip 检测),
  • 主机名单,最近访问和未解析的 IP 地址名单
  • 大多数看过的进出页面,
  • 档案类型,
  • 网站压缩统计表(mod_gzip 或者 mod_deflate),
  • 使用的操作系统 (每个操作系统的页数,点击率 ,字节, 35 OS detected),
      使用的浏览器,
  • 机器人访问(检测 319 个机器人),
  • 蠕虫攻击 (5 个蠕虫家族),
  • 搜索引擎,利用关键词检索找到你的地址,
  • HTTP 协议错误(最近查阅没有找到的页面),
  • 其他基于 URL 的个性报导,链接参数, 涉及综合行销领域目的.
  • 贵网站被加入”最喜爱的书签”.次数.
  • 屏幕大小(需要在索引页补充一些 HTML 标签).
  • 浏览器的支持比例: Java, Flash, RealG2 reader, Quicktime reader, WMA reader, PDF reader.
  • 负载平衡服务器比率集群报告.

Awstats 的运行是需要 PERL 环境的支持

yingouqlj@qljlearnhost:~$ perl -version
 
This is perl, v5.10.0 built for i486-linux-gnu-thread-multi
 
Copyright 1987-2007, Larry Wall
 
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
 
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
 
yingouqlj@qljlearnhost:~$

修改NGINX网站配置

yingouqlj@qljlearnhost:~$ sudo vim /etc/nginx/sites-enabled/default
[sudo] password for yingouqlj:
# You may add here your
# server {
#       ...
# }
# statements for each of your virtual hosts
 
server {
        listen   80;
        server_name my.qlj.sh.cn;
 
        location / {
                root   /var/www/nginx-default;
                 index index.php  index.html index.htm;
        }
 
#.....省略
 
   log_format  default  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
    access_log  /home/yingouqlj/logs/access.log  default;
 
#.....省略
}

安装AWSTATS
WGET下载
解压到 /usr/local/awstats
然后执行 tools 目录中的 awstats_configure.pl

第一步
Config file path (‘none’ to skip web server setup):

输入none跳国 我们不是APACHE

第二步
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ?
#> y

#y 创建一个新的统计配置

第三步
—–> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
#> my.qlj.sh.cn

然后一路回车下去
最后看到
Press ENTER to finish…

生成静态的文件
我保存为脚本 方便执行

/usr/local/awstats/tools/awstats_buildstaticpages.pl -update  -config=my.qlj.sh.cn  -lang=cn -dir=/var/www/nginx-default/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl

/usr/local/awstats/tools/awstats_buildstaticpages.pl Awstats 静态页面生成工具
-update -config=my.qlj.sh.cn 更新配置项
-lang=cn 语言为中文
-dir=/var/www/nginx-default/awstats 统计结果输出目录
awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl Awstats 日志更新程序路径。

yingouqlj@qljlearnhost:~/cron_list$ ./awstatcreat.sh
Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -update -configdir=
Build main page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output
Build alldomains page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=alldomains
Build allhosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=allhosts
Build lasthosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=lasthosts
Build unknownip page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=unknownip
Build allrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=allrobots
Build lastrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=lastrobots
Build session page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=session
Build urldetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=urldetail
Build urlentry page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=urlentry
Build urlexit page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=urlexit
Build osdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=osdetail
Build unknownos page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=unknownos
Build browserdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=browserdetail
Build unknownbrowser page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=unknownbrowser
Build refererse page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=refererse
Build refererpages page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=refererpages
Build keyphrases page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=keyphrases
Build keywords page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=keywords
Build errors404 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=my.qlj.sh.cn -staticlinks -lang=cn -output=errors404
20 files built.
Main HTML page is 'awstats.my.qlj.sh.cn.html'.
yingouqlj@qljlearnhost:~/cron_list$

Main HTML page is ‘awstats.my.qlj.sh.cn.html‘.
访问这个文件 就OK 了
看下结果吧

Leave a Reply