CentOS下使用AWStats分析Nginx访问日志
时间:2014-11-20 20:41 来源:linux.it.net.cn 作者:IT
-
访问量(UV),访问次数,页面浏览量(PV),点击数,数据流量等
-
精确到每月、每日、每小时的数据
-
访问者国家
-
访问者IP
-
Robots/Spiders的统计
-
访客持续时间
-
对不同Files type的统计信息
-
Pages-URL的统计
-
访客操作系统浏览器等信息
-
其它信息(搜索关键字等等)
log_format access '$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/access.log access;
shell# nginx -t && nginx -s reload
#!/bin/bash
#
# Filename: nginxCutLog.sh
# Author: Qicheng
# Website: http://qicheng0211.blog.51cto.com/
# Description: 切割nginx日志
# Notes: 设置crontab,每天23点59分定时执行
#
ROOT_UID=0
if [ "$UID" -ne "$ROOT_UID" ];then
echo "Error: 必须以root用户运行此程序!"
exit 1
fi
nginx_logs_dir="/var/log/nginx"
nginx_pid_file="/var/run/nginx.pid"
# 切割后的日志文件名,例如access_20141022.log
nginx_log_today="$nginx_logs_dir/access_`date +%Y%m%d`.log"
[ -f "$nginx_log_today" ] && exit 1
mv $nginx_logs_dir/access.log $nginx_log_today
# 给nginx发送USR1信号,使重新打开新的access.log日志文件
[ -f $nginx_pid_file ] && /bin/kill -USR1 $(cat $nginx_pid_file)
59 23 * * * /bin/bash /yourscriptpath/nginxCutLog.sh
shell# wget http://awstats.sourceforge.net/files/awstats-7.0.tar.gz
shell# tar -zxvf awstats-7.0.tar.gz
shell# mv awstats-7.0 /usr/local/awstats
shell# mkdir -p /var/lib/awstats
shell# cd /usr/local/awstats/tools/
shell# ./awstats_configure.pl
LogFile="/var/log/nginx/access_%YYYY-24%MM-24%DD-24.log"
shell# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=yourwebsite
shell# mkdir -p /var/www/awstats
shell# /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=yourwebsite -lang=cn -dir=/var/www/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
1 0 * * * /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=yourwebsite -lang=cn -dir=/var/www/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
shell# yum -y install httpd-tools
shell# htpasswd -cd admin.pass admin
New password:
Re-type new password:
Adding password for user admin
server {
listen 83;
server_name localhost;
location ~ ^/awstats/ { # html 静态页面目录
root /var/www;
index index.html;
access_log off;
error_log off;
charset gb2312;
auth_basic "admin";
auth_basic_user_file admin.pass;
}
location ~ ^/icon/ { # 图标目录
root /usr/local/awstats/wwwroot;
index index.html;
access_log off;
error_log off;
}
}
(责任编辑:IT)
(责任编辑:IT) |


