nginx日志的默认格式不能被awsats所分析,不然就要更改nginx的log日志格式,相比较而言,nginx更改log日志仍是比较方便的,只是没有apache的log日志那么简单而已。废话很少说,下面就是详细的awstats分析log日志的格式。nginx
1.自定义nginx的日志格式,便于awstats分析
awstats分析的日志格式必须为:111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] "GET / HTTP/1.1" 200 1234 "http://www.fromserver.com/from.htm" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
And this is an example of records AWStats found in your log file (the record number 50 in your log):
nginx配置logformat:
sql
- log_format new_log '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- access_log /usr/local/nginx/logs/access.log new_log;
狗了一下,网上有2种配置方法,若是格式不对的话,能够更改成:apache
- log_format new_log '$remote_addr - $remote_user [$time_local] $request '
- '"$status" $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- access_log /usr/local/nginx/logs/access.log new_log;
而后重启nginx,只要日志的格式符合awstats分析就能够了。ide
个人日志配置有点郁闷,一开始配置的都是第2种的格式,可是有一台nginx输出的日志和awstats分析的日志格式不同,更改成第一种的格式"$request"的就能够了。2种日志配置方法代码不同的地方已经用红色标出来了,请你们注意。。。this