Apache日志的设置

2010-10-21

本文转自:<http://www.ccvita.com/298.html >

错误日志的设置

ErrorLog logs/error_log #日志的保存位置

LogLevel warn #日志的级别

显示的格式日下:

[Mon Oct 10 15:54:29 2005] [error] [client 192.168.10.22] access to /download/ failed, reason: user admin not allowed access

访问日志设置

日志的缺省格式有如下几种

LogFormat “%h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i”" combined
LogFormat “%h %l %u %t “%r” %>s %b” common #common为日志格式名称
LogFormat “%{Referer}i -> %U” referer
LogFormat “%{User-agent}i” agent
CustomLog logs/access_log common

格式中的各个参数如下:

%h –客户端的ip地址或主机名

%l –The 这是由客户端 identd 判断的RFC 1413身份,输出中的符号 “-” 表示此处信息无效。

%u –由HTTP认证系统得到的访问该网页的客户名。有认证时才有效,输出中的符号 “-” 表示此处信息无效。

%t –服务器完成对请求的处理时的时间。

“%r” –引号中是客户发出的包含了许多有用信息的请求内容。

%>s –这个是服务器返回给客户端的状态码。

%b –最后这项是返回给客户端的不包括响应头的字节数。

“%{Referer}i” –此项指明了该请求是从被哪个网页提交过来的。

“%{User-Agent}i” –此项是客户浏览器提供的浏览器识别信息。

下面是一段访问日志的实例:

192.168.10.22 - bearzhang [10/Oct/2005:16:53:06 +0800] “GET /download/ HTTP/1.1″ 200 1228

192.168.10.22 - - [10/Oct/2005:16:53:06 +0800] “GET /icons/blank.gif HTTP/1.1″ 304 -

192.168.10.22 - - [10/Oct/2005:16:53:06 +0800] “GET /icons/back.gif HTTP/1.1″ 304 -

各参数的详细解释,请参阅:http://www.clusting.com/Apache/ApacheManual/logs.h...