我想使用 AwStats 来解析 nginx 访问日志。
指定的 nginx 日志格式为
'$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
并且日志似乎创建正确。
AwStats 日志格式为
LogFormat = "%host - %logname %time1 %code %methodurl %bytesd %refererquot %uaquot %otherquot"
当我尝试从命令行运行它时,收到以下错误输出:
Running '"/usr/lib/cgi-bin/awstats.pl" -update -config=default -configdir="/etc/awstats"' to update config default
Create/Update database for config "/etc/awstats/awstats.conf" by AWStats version 7.2 (build 1.992)
From data in log file "/.../****-access.log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
AWStats did not find any valid log lines that match your LogFormat parameter, in the 50th first non commented lines read of your log.
Your log file /.../****-access.log must have a bad format or LogFormat parameter setup does not match this format.
Your AWStats LogFormat parameter is:
%host - %logname %time1 %code %methodurl %bytesd %refererquot %uaquot %otherquot
This means each line in your web server log file need to have the following personalized log format:
%host - %logname %time1 %code %methodurl %bytesd %refererquot %uaquot %otherquot
And this is an example of records AWStats found in your log file (the record number 50 in your log):
1.2.3.4 - - [20/Sep/2015:14:18:24 +0200] 200 "POST /somescript.php HTTP/1.1" 1277 "http://some.refer.er" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0" "-"
Setup ('/etc/awstats/awstats.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).
我已经尝试了几个不同的变量(我最初遵循的教程有%code
并%methodurl
切换并使用%host_r
而不是%logname
),但到目前为止我还没有让它发挥作用。
我甚至尝试用 替换%logname
,-
因为我认为缺少的远程用户名可能会混淆 AwStats,但无济于事。
对我来说,日志格式和错误消息中的实际日志行看起来应该匹配。我错过了什么?
答案1
这是我在 awstats 中必须使用的日志配置才能使其正常工作。
LogFormat = "%host %other %other %time1 %methodurl %code %bytesd %refererquot %uaquot"
这是基于 nginx 的现成日志格式