0

0

awstats统计分析nginx日志

php中文网

php中文网

发布时间:2016-06-07 15:30:30

|

1661人浏览过

|

来源于php中文网

原创

#修改nginx日志格式: log_format awstats '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/live.yofogo.com.access.log awstats; #

#修改nginx日志格式:
  log_format awstats '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
  access_log  logs/live.yofogo.com.access.log  awstats;

#nginx切割日志脚本logcron.sh:
  mv  /opt/nginx/nginx-1.2.1/logs/live.yofogo.com.access.log /opt/nginx/nginx-1.2.1/logs/live.yofogo.com.access_`date +%y%m%d`.log
  killall -s usr1 nginx #使用usr1参数通知nginx进程切换日志文件

#安装awstats
  wget http://prdownloads.sourceforge.net/awstats/awstats-7.0.tar.gz
  tar xzf awstats-7.0.tar.gz
  mv awstats-7.0 /usr/local/awstats
  cd /usr/local/awstats/tools
     chmod +x /usr/local/awstats/tools/*.pl
     chmod +x wwwroot/cgi-bin/*.pl
  mkdir /etc/awstats /var/lib/awstats

#awstats配置
  cd /usr/local/awstats/tools
  perl awstats_configure.pl:
    -----> 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 files\apache group\apache\conf\httpd.conf
    config file path ('none' to skip web server setup):
    #> none  回车#因为这里用的是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/awstats/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    回车#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:
    #> live.yofogo.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):
    #> 回车

    ----> 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/awstats/wwwroot/cgi-bin/awstats.pl -update -config=live.yofogo.com  
        #回头把该命令填入crontab 按指定时间执行
    or if you have several config files and prefer having only one command:
    /usr/local/awstats/tools/awstats_updateall.pl now
    press enter to continue...        回车

    a simple config file has been created: /etc/awstats/awstats.live.yofogo.com.conf  
        #新配置文件所在的路径
    you should have a look inside to check and change manually main parameters.
    you can then manually update your statistics for 'live.yofogo.com' with command:
    > perl awstats.pl -update -config=live.yofogo.com
    you can also build static report pages for 'live.yofogo.com' with command:
    > perl awstats.pl -output=pagetype -config=live.yofogo.com
    press enter to finish...回车

  #编辑awstats配置文件:sudo vim /etc/awstats/awstats.live.yofogo.com.conf
          logfile="/opt/nginx/nginx-1.2.1/logs/live.yofogo.com.access_%yyyy-0%mm-0%dd-0.log" //统计的日志文件的路径
          logformat=1//日志格式,这个一定要跟要分析的日志格式匹配,不然可能分析不出来数据或者分析出来的数据不正确
          logseparator=" "//指定日志的分割符
          sitedomain="www.lme.pw"//要分析的网站域名
          dirdata="/opt/awstats"//分析完的数据文件存在的位置
          lang为lang="cn"
          #对应nginx日志切割所生成的目录存放结构,要注意awstats的年月日格式的跟nginx的写法不同。现在执行统计的顺序是:
      nginx 产生日志 –> 日志切割 –> nginx 继续产生日志 –> 另存切割日志 –> 交由awstats统计 –> 生成结果

#awstats静态文件统计资源配置
  mkdir -p /home/works/yofoto/awstats-web/awstats
  #cp -r /usr/local/awstats/wwwroot/css /home/works/yofoto/awstats-web
  #cp -r /usr/local/awstats/wwwroot/icon /home/works/yofoto/awstats-web
  #nginx映射:
    location ~ ^/awstats/ {# html 静态页面目录
        root   /home/works/yofoto/awstats-web;
        index  index.html;
        access_log off;
        error_log off;
        charset gb2312; #最好把默认编码改成 gb2312避免浏览器因自动编码出现乱码的情况
    }

    location ~ ^/icon/ {# 图标目录
        root   /usr/local/awstats/wwwroot;
        index  index.html;
        access_log off;
        error_log off;
        charset gb2312;
    }
  #更新日志统计数据库及生成静态文件到指定目录
    /usr/local/awstats/tools/awstats_buildstaticpages.pl -update  \
  -config=live.yofogo.com -lang=cn -dir=/home/works/yofoto/awstats-web/awstats  \
  -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl

  #上述命令的具体意思如下:
    /usr/local/awstats/tools/awstats_buildstaticpages.pl awstats 静态页面生成工具
    -update -config=live.yofogo.com 更新配置项
    -lang=cn 语言为中文
    -dir=/home/works/yofoto/awstats-web/awstats 统计结果输出目录
    -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl awstats日志更新程序路径

#浏览器查看统计结果 http://youhostname/awstats/awstats.live.yofogo.com.html

#配置awstats自动日志统计-设置crontab计划任务:
  sudo vim /etc/crontab
    #下午15:00进行日志切割
    15 00 * * * /opt/nginx/nginx-1.2.1/sbin/logcron.sh
    #下午15:20进行日志分析
    15 20 * * * /usr/local/awstats/tools/awstats_buildstaticpages.pl -update  \
     -config=live.yofogo.com -lang=cn -dir=/home/works/yofoto/awstats-web/awstats  \
     -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl    
  #crontab /etc/crontab    指定cron所执行的配置档路径

#保护日志统计结果页面

     用htpasswd生成密钥,

     location ~ ^/awstats/ {# html 静态页面目录
         root /home/works/yofoto/awstats-web;
         index index.html;
         access_log off;
         error_log off;
         charset gb2312;
         auth_basic "admin";
         auth_basic_user_file /home/works/yofoto/awstats-web/passwd.pass;
     }

C2C电子商务二手交易网站
C2C电子商务二手交易网站

全部实现了C2C电子商务功能,特别适合高校、组织、社区实现自己的C2C电子商务 前台: 1.用户快速注册,可限制IP段 2.用户发布供求信息 3.信息分类、信息有效期 4.信息各种搜索功能 5.网站日志 6.网站留言板 7.站内通信功能(用户小纸条) 8.用户自主管理信息,修改信息状态,修改信息 9.网站各项统计 10.信息推送

下载
检测配置/nginx/sbin/nginx -t -c /nginx/conf/nginx.conf
执行命令killall –s HUP nginx 让 Nginx重新加载配置即可
清除80端口的进程: lsof -i :80|grep -v "PID"|awk '{print "kill -9",$2}'|sh

参考:
  http://www.ibm.com/developerworks/cn/linux/l-cn-awstats-nginx
  http://www.linuxyan.com/web-server/102.html
  http://blog.rebill.info/archives/statistical-analysis-of-user-behavior-system-architecture-design.html

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
go语言 注释编码
go语言 注释编码

本专题整合了go语言注释、注释规范等等内容,阅读专题下面的文章了解更多详细内容。

2

2026.01.31

go语言 math包
go语言 math包

本专题整合了go语言math包相关内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

go语言输入函数
go语言输入函数

本专题整合了go语言输入相关教程内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

golang 循环遍历
golang 循环遍历

本专题整合了golang循环遍历相关教程,阅读专题下面的文章了解更多详细内容。

0

2026.01.31

Golang人工智能合集
Golang人工智能合集

本专题整合了Golang人工智能相关内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

2026赚钱平台入口大全
2026赚钱平台入口大全

2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。

76

2026.01.31

高干文在线阅读网站大全
高干文在线阅读网站大全

汇集热门1v1高干文免费阅读资源,涵盖都市言情、京味大院、军旅高干等经典题材,情节紧凑、人物鲜明。阅读专题下面的文章了解更多详细内容。

73

2026.01.31

无需付费的漫画app大全
无需付费的漫画app大全

想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。

67

2026.01.31

漫画免费在线观看地址大全
漫画免费在线观看地址大全

想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。

19

2026.01.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
CSS3 教程
CSS3 教程

共18课时 | 5万人学习

Git 教程
Git 教程

共21课时 | 3.2万人学习

SciPy 教程
SciPy 教程

共10课时 | 1.3万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号