温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nginx中怎么实现AWStats静态页面

发布时间:2021-08-09 14:57:18 来源:亿速云 阅读:113 作者:Leah 栏目:web开发

这期内容当中小编将会给大家带来有关Nginx中怎么实现AWStats静态页面,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

1. 下载***版的AWStats,基本就是Perl包,所以没必要用apt-get,解压缩到/usr/local/awstats下

wget http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz
tar -xzf awstats-6.95.tar.gz
mv awstats-6.95 /usr/local/awstats

2. 创建一个存放awstats分析数据的目录

mkdir /var/lib/awstats
chown www-data /var/lib/awstats //这是为了让awstats页面上能直接刷新***数据

3. 自动配置awstats

cd /usr/local/awstats/tools
perl awstats_configure.pl

除了***步因为是Ngin服务器的关系,所以要选none,其他基本按照提示选默认值

4. 手工编辑Nginx配置文件

1) 修改LogFile路径

LogFile = “/var/log/Nginx/access.log”

如果是压缩格式的日志,可以用LogFile = “zcat /var/log/Nginx/%YYYY-24%MM-24%DD-24.gz|"。这里用zcat是因为其使用管道输出,对系统资源消耗比较小,千万不要忘了***的管道操作符!

假设原来/etc/Nginx/Nginx.conf中关于log部分是如此定义的:(要小心各个变量之间必须添加的空格,不能少,否则awstats就不认了)

log_format main ‘$remote_addr $remote_user [$time_local] “$request” $status ‘
‘$host $body_bytes_sent $gzip_ratio “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

很容易知道,对应awstats配置文件中,LogFormat应该设置为
LogFormat= “%host %logname %time1 %methodurl %code %host_r %bytesd %gzipratio %refererquot %uaquot %otherquot”

***一个选%otherquot是应为$http_x_forwarded_for在AWstats 6.95中还不认识

3) 将AllowToUpdateStatsFromBrowser=1,便于浏览器中即时刷新数据

5. 更新Awstats的分析记录,测试一下刚才的配置

/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=yousite.com

如果一切正常,应该看到类似以下的结果:

Create/Update database for config “/etc/awstats/awstats.yoursite.com.conf” by AWStats version 6.95 (build 1.943)
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: 1234
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 1234 new qualified records.

6. 修改logrotate.d下的Nginx配置文件,在每天切割日志前,更新awstats状态

/var/log/  nginx  /*.log {  daily  missingok  rotate 7  compress  delaycompress  notifempty  create 640 www-data www-data  dateext  sharedscripts  prerotate  /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=yoursite.com  sleep 59  endscript  postrotate  if [ -f /var/run/nginx.pid ]; then  kill -USR1 `cat /var/run/nginx.pid`  fi  endscript  }

7. 接下来是最关键的NGINX配置文件

#AWStatus Perl CGI server  server {  listen 80;  server_name awstats.yoursite.com;  access_log /var/log/nginx/awstats.log main;  error_log /var/log/nginx/awstats_error.log; #这可以为fail2ban留下记录  root /usr/local/awstats/wwwroot;  auth_basic “Restricted”;  auth_basic_user_file /etc/nginx/awstatus.pass;  location = / {  rewrite ^ /awstats.pl?config=freshventure.info;  }  location ~ .*(\.cgi|\.pl?)$ {  gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped  root /usr/local/awstats/wwwroot/cgi-bin;  fastcgi_pass 127.0.0.1:8000;  fastcgi_index awstats.pl;  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  include fastcgi_params;  }  }

好了,测试一下http://awstats.yoursite.com,和前文一样,输入密码后,这次看到的应该就awstats的界面了

8. 如果需要配置静态页面,则可以在logrotate中替换掉上面的awstats.pl, 换成

/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=yoursite.com -lang=cn -dir=/usr/local/awstats/wwwroot -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl。

上述就是小编为大家分享的Nginx中怎么实现AWStats静态页面了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI