请联系我 有广告合作意向的 请联系我

AWstats 分析Nginx访问日志

AWstats下载地址:http://nchc.dl.sourceforge.net/project/awstats/AWStats/7.0/awstats-7.0.zip

1、下载后的解压文件并拷贝到/usr/local/awstart/下

2、执行tools 目录中的 awstats_configure.pl 配置向导
[root@zhouda tools]# perl awstats_configure.pl

—– AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur —–
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
– You are not an administrator user,
– You want to analyze downloaded log files without web server,
– You want to analyze mail or ftp log files instead of web log files,
– You need to analyze load balanced servers log files,
– You want to ‘understand’ all possible ways to use AWStats…
Read the AWStats documentation (docs/index.html).

—–> Running OS detected: Linux, BSD or Unix
Warning: AWStats standard directory on Linux OS is ‘/usr/local/awstats’.
If you want to use standard directory, you should first move all content
of AWStats distribution from current directory:
/usr/local/awstart
to standard directory:
/usr/local/awstats
And then, run configure.pl from this location.
Do you want to continue setup from this NON standard directory [yN] ? y

—–> Check for web server install

Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:Program filesapache groupapacheconfhttpd.conf
Config file path (‘none’ to skip web server setup):
> none #由于要统计的不是Apache而是nginx日志,所以none

Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)

—–> Update model config file ‘/usr/local/awstart/wwwroot/cgi-bin/awstats.model.conf’
File awstats.model.conf updated.

—–> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? 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:
> www.a.com

—–> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
> #默认的配置文件路径/etc/awstats

—–> Create config file ‘/etc/awstats/awstats.www.a.com.conf’
Config file /etc/awstats/awstats.www.a.com.conf created.

—–> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstart/wwwroot/cgi-bin/awstats.pl -update -config=www.a.com
#添加到计划任务里面定时更新
Or if you have several config files and prefer having only one command:
/usr/local/awstart/tools/awstats_updateall.pl now
Press ENTER to continue…
A SIMPLE config file has been created: /etc/awstats/awstats.www.a.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for ‘www.a.com’ with command:
> perl awstats.pl -update -config=www.a.com
You can also build static report pages for ‘www.a.com’ with command:
> perl awstats.pl -output=pagetype -config=www.a.com

Press ENTER to finish…

3、编辑配置文件/etc/awstats/awstats.www.test.com.conf

找到LogFile=”/var/log/httpd/mylog.log”
修改成nginx日志文件的正确位置
LogFile=”/var/log/nginx/access.log”
保存,退出。

4、修改Nginx 日志文件生成格式————适应awstats的需要
log_format  main  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;
以上内容保存到配置文件并重启下Nginx.

由于在配置日志分析之前网站已经运行了一段时间,所以需要把现有的日志给清除掉,因为格式不匹配
# echo ” ” > /var/log/nginx/access.log

5、手动运行统计脚本:(添加到cron 任务中)
[root@zhouda awstats]# perl /usr/local/awstart/wwwroot/cgi-bin/awstats.pl -update -config=www.a.com
Create/Update database for config “/etc/awstats/awstats.www.a.com.conf” by AWStats version 7.0 (build 1.971)
From data in log file “/var/log/nginx/access.log”…
Phase 1 : First bypass old records, searching new record…
Searching new records from beginning of log file…
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)…
Jumped lines in file: 0
Parsed lines in file: 195
Found 0 dropped records,
Found 0 comments,
Found 1 blank records,
Found 1 corrupted records,
Found 0 old records,
Found 193 new qualified records.
# 出现上面的输出,表示没问题可以继续.

6、都说nginx对cgi支持不是很好,那用静态输出得了……
[root@zhouda ~]# perl /usr/local/awstart/tools/awstats_buildstaticpages.pl -update -config=www.a.com  -lang=cn -dir=/www -awstatsprog=/usr/local/awstart/wwwroot/cgi-bin/awstats.pl
Launch update process : “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -update -configdir=
Build main page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output
Build alldomains page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=alldomains
Build allhosts page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=allhosts
Build lasthosts page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=lasthosts
Build unknownip page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=unknownip
Build allrobots page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=allrobots
Build lastrobots page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=lastrobots
Build session page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=session
Build urldetail page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=urldetail
Build urlentry page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=urlentry
Build urlexit page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=urlexit
Build osdetail page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=osdetail
Build unknownos page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=unknownos
Build browserdetail page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=browserdetail
Build unknownbrowser page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=unknownbrowser
Build refererse page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=refererse
Build refererpages page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=refererpages
Build keyphrases page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=keyphrases
Build keywords page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=keywords
Build errors404 page: “/usr/local/awstart/wwwroot/cgi-bin/awstats.pl” -config=www.a.com -staticlinks -lang=cn -output=errors404
20 files built.
Main HTML page is ‘awstats.www.a.com.html’.

最后一步配置Nginx输出那个页面:http://www.a.com/awstats.www.a.com.html
并把上面那条命令放到任务中,多长时间执行一次,自己看着办喽

关于显示IP地址地区的配置:
1. 首先下载插件(qqhostinfo.pm)。把它放在/usr/local/awstat/wwwroot/cgi-bin/plugins中。
2. 下载分析QQWry.dat的perl脚本(qqwry.pl)。放在同一目录。
3. 修改,qqwry.pl中:
./QQWry.Dat 修改为 ${DIR}/plugins/QQWry.Dat
4. 去网上下载QQWry.Dat放在同一目录中 下载(http://www.cz88.net/fox/),注意文件名一定要是QQWry.Dat
5. 编辑你得awstats配置文件,大概在LoadPlugin=”hostinfo”的后面增加一行
LoadPlugin=”qqhostinfo”
重新运行上面第五、六步

常见错误解决:

一、AWStats搜索关键词中文出现乱码解决办法
1. 修改站点配置文件awstats.www.test.com.conf
把LoadPlugin=”decodeutfkeys”前边的#去掉
2. 安装Perl模块

二、[root@www nginx]#cpan
cpan> install Encode
cpan> install URI::Escape
重新运行上面第五、六步。

2 Comments

Add a Comment

电子邮件地址不会被公开。 必填项已用*标注