awstats 可以通过apache 部署,关联指定格式的日志文件(apache,nginx),然后通过网页的形式展现出来,便于观察分析。
现有的通过apache部署的项目,想要方便的查看access_log,可以通过集成AWStats。给AWStats目录添加访问权限验证。
1,
安装perl.
去官网下载并安装到D:/Strawberry目录。
perl -v 查看perl是否安装成功,并可以执行(已经加入环境变量Path)。
2,
下载awstats,并解压到D:\wamp\Apache22\htdocs\awstats.
http://www.awstats.org/#DOWNLOAD
先把网站运行起来,确保在安装前是可以运行的,然后
D:\wamp\Apache22\htdocs\awstats\tools>perl awstats_configure.pl
按提示操作:
在执行完成后,将添加的不正确的内容删掉,替换为以下内容。
#
# Directives to add to your Apache conf file to allow use of AWStats as a CGI.
# Note that path "/usr/local/awstats/" must reflect your AWStats Installation path.
#
Alias /awstatsclasses "D:/wamp/Apache22/htdocs/awstats/wwwroot/classes/"
Alias /awstatscss "D:/wamp/Apache22/htdocs/awstats/wwwroot/css/"
Alias /awstatsicons "D:/wamp/Apache22/htdocs/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "D:/wamp/Apache22/htdocs/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "D:/wamp/Apache22/htdocs/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
#AuthType Basic
#AuthName "Awstats"
#AuthUserFile D:/wamp/Apache22/htdocs/awstats/wwwroot/passwd/passwords
#Require user awstats
</Directory>
日志按天分段进行保存:
httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster@www.a.com
DocumentRoot "D:/wamp/Apache22/htdocs/bxx"
ServerName www.a.com
ErrorLog "|D:/wamp/Apache22/bin/rotatelogs.exe logs/www.a.com-%Y_%m_%d.error.log 86400 480"
#CustomLog "logs/www.a.com.log" combined
CustomLog "|D:/wamp/Apache22/bin/rotatelogs.exe logs/www.a.com-%Y_%m_%d.access_log.log 86400 480" combined
</VirtualHost>
D:\awstats-7.6\wwwroot\cgi-bin\awstats.www.a.com.conf(相关配置):
LogFile="D:/wamp/Apache22/logs/www.a.com-%YYYY-0_%MM-0_%DD-0.access_log.log"
D:\wamp\Apache22\htdocs\awstats\wwwroot\cgi-bin\awstats.pl 开始处修改为自己安装的perl的路径,eg:
#!D:/Strawberry/perl/bin/perl.exe
通过
D:\awstats-7.6\wwwroot\cgi-bin>perl awstats.pl -update -config=www.a.com
更新日志信息,使得awstats可以访问最新的日志,可以设置一个定期任务(一天执行一次)。
通过
http://www.a.com/awstats/awstats.pl?config=www.a.com
访问日志详情。
现在我想这个页面需要认证才能查看,首先生成认证用的用户名和密码:
D:\wamp\Apache22\bin>
htpasswd.exe -cb D:/wamp/Apache22/htdocs/awstats/wwwroot/pa
sswords awstats 123456
Adding password for user awstats
在httpd.conf 中,添加认证信息,重启服务器。
通过
http://www.a.com/awstats/awstats.pl?config=www.a.com
访问日志详情,出现认证界面,输入认证信息,进入详细界面。
如果做完了以上内容,达不到相应结果,请参考以下文件内容修改apache和awstats的配置,
httpd.conf:
ServerRoot "D:/wamp/Apache22"
Listen 80
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule php5_module "d:/wamp/php/php5apache2_2.dll"
PHPIniDir "d:/wamp/php"
AddType application/x-httpd-php .php .phtml
DocumentRoot "D:/wamp/Apache22/htdocs"
<Directory />
Options FollowSymLinks +ExecCGI
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "D:/wamp/Apache22/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.php index.php3 index.html index.htm index.cgi
</IfModule>
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
ErrorLog "logs/error.log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "|D:/wamp/Apache22/bin/rotatelogs.exe logs/www.a.com-%Y_%m_%d.access_log.log 86400 480" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "D:/wamp/Apache22/cgi-bin/"
</IfModule>
<Directory "D:/wamp/Apache22/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
# Fancy directory listings
Include conf/extra/httpd-autoindex.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# Directives to add to your Apache conf file to allow use of AWStats as a CGI.
# Note that path "/usr/local/awstats/" must reflect your AWStats Installation path.
#
Alias /awstatsclasses "D:/wamp/Apache22/htdocs/awstats/wwwroot/classes/"
Alias /awstatscss "D:/wamp/Apache22/htdocs/awstats/wwwroot/css/"
Alias /awstatsicons "D:/wamp/Apache22/htdocs/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "D:/wamp/Apache22/htdocs/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "D:/wamp/Apache22/htdocs/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthType Basic
AuthName "Awstats"
AuthUserFile D:/wamp/Apache22/htdocs/awstats/wwwroot/passwords
Require user awstats
</Directory>
httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster@www.a.com
DocumentRoot "D:/wamp/Apache22/htdocs/bxx"
ServerName www.a.com
ErrorLog "|D:/wamp/Apache22/bin/rotatelogs.exe logs/www.a.com-%Y_%m_%d.error.log 86400 480"
#CustomLog "logs/www.a.com.log" combined
CustomLog "|D:/wamp/Apache22/bin/rotatelogs.exe logs/www.a.com-%Y_%m_%d.access_log.log 86400 480" combined
</VirtualHost>
D:\awstats-7.6\wwwroot\cgi-bin\awstats.www.a.com.conf(相关配置):
#LogFile="D:/wamp/Apache22/logs/www.a.com.log"
#LogFile="D:/wamp/Apache22/logs/www.a.com-%YYYY-24_%MM-24_%DD-24.access_log.log"
LogFile="D:/wamp/Apache22/logs/www.a.com-%YYYY-0_%MM-0_%DD-0.access_log.log"
LogType=W
LogFormat=1
LogSeparator=" "
SiteDomain="www.a.com"
HostAliases="a.com www.a.com 127.0.0.1 localhost"
mind:#更新日志信息,使得awstats可以访问最新的日志,可以设置一个定期任务(一天执行一次)。
D:\awstats-7.6\wwwroot\cgi-bin>perl awstats.pl -update -config=www.a.com
https://awstats.sourceforge.io/docs/awstats_setup.html
http://www.awstats.org/docs/awstats_compare.html
http://www.linuxidc.com/Linux/2012-08/68004.htm
http://www.showerlee.com/archives/757
https://awstats.sourceforge.io/docs/awstats_config.html#LogFile