在Debian上安装AWStats

时间:2020-03-21 11:45:18  来源:igfitidea点击:

安装AWStats <以分析Apache日志文件。

安装

本文假定我们已安装并正在运行Apache Web服务器。

# apt-get install awstats

配置

打开“ /etc/awstats/awstats.conf”进行编辑,然后更改以下几行:

# This is where your Apache log goes
LogFile="/var/log/apache2/access.log"
# For Apache combined logs
LogFormat=1
# The main domain name used to reach the website
SiteDomain="www.example.com"
HostAliases="localhost 127.0.0.1"
DirIcons="./icon"

为awstats创建一个webroot:

# mkdir /var/www/awstats 
# ln -s /usr/share/awstats/icon /var/www/awstats/icon

创建一个配置文件:

# touch /etc/apache2/sites-available/awstats.conf

打开上面的文件进行编辑,并添加以下几行:

<VirtualHost *:80>

ServerAdmin Hyman@theitroad

ServerName awstats.example.com

DocumentRoot /var/www/awstats

<Directory

AuthGroupFile /dev/null

AuthType Basic

AuthUserFile /var/www/awstats/.htpasswd

AuthName "Access Restricted"

Require valid-user

AuthType Basic

Order deny,allow

Deny from all

Allow from 10.0.0.0/8

</Directory>

ScriptAlias /cgi-bin//usr/lib/cgi-bin/

<Directory "/usr/lib/cgi-bin">

AllowOverride None

Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

Order deny,allow

Deny from all

Allow from 10.0.0.0/8

</Directory>
</VirtualHost>

更改上面的子网(10.0.0.0/8)以匹配网络配置。

为用户sandy创建新的密码“ .htpasswd”文件,以进行基本的Apache身份验证:

# htpasswd -c /var/www/awstats/.htpasswd sandy

启用awstats:

# cd /etc/apache2/sites-available/
# a2ensite awstats.conf

测试配置:

# apachectl configtest
Syntax OK

重新启动Apache:

# /etc/init.d/apache2 restart

产生报告

# /usr/lib/cgi-bin/awstats.pl -config=apache -update
# /usr/lib/cgi-bin/awstats.pl -config=apache -output -staticlink > /var/www/awstats/index.html

每小时自动生成报告:

# crontab -l
0 * * * * /usr/lib/cgi-bin/awstats.pl -config=apache -update
5 * * * * /usr/lib/cgi-bin/awstats.pl -config=apache -output -staticlink > /var/www/awstats/index.html