查找Apache日志上使用的格式

时间:2013-11-14 22:11:44

标签: apache http logging

我正在尝试对传递给我的一组Apache访问日志执行一些数据分析,但我注意到这些日志似乎不是传统的格式(基于我发现的一些其他Apache日志示例)线上)。以下是从我的一个日志文件中提取的一行(在一些匿名化之后):

2013-08-25 10:06:11 EDT - "GET http://www.siteaddress.com/section/aaa/z/directory HTTP/1.1" 404 1677 1.2.181.171 "-" "Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)" - 0 155311 -

有什么办法可以找出用于记录这些日志的格式吗?也就是说,我该如何为这个文件获取某种标题? Ps。:我可以访问捕获这些日志的服务器,并可以使用它来查找该信息。

编辑1:我被告知检查 /etc/apache2/httpd.conf 的内容,我发现这是空的。

编辑2: apache2.conf 中找到了以下相关内容,但我不太确定这些内容与我在日志中看到的相符。

# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""  vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

编辑3: / etc / apache2 / sites-available / hub 中找到它,它似乎与我的格式匹配(非常感谢!)

LogFormat "%{%Y-%m-%d %H:%M:%S %Z}t %u \"%r\" %>s %B %a \"%{Referer}i\" \"%{User-Agent}i\" - %T %D -"

2 个答案:

答案 0 :(得分:1)

在基于debian的发行版中,配置被分成多个文件。主要配置为/etc/apache2/apache2.conf,而所有vHost(默认情况下使用)都在/etc/apache2/sites-available中配置(当使用a2ensite在/ etc中使用符号链接激活虚拟主机时,它们可能不活动创建/ apache2 / sites-enabled /,从中包含文件)

如果您从未搞砸配置,则应设置日志格式 apache2.conf中/etc/apache2/sites-available/default容器内的VirtualHost

答案 1 :(得分:1)

您可以在其中一个Apache配置文件中找到格式规范;取决于您的服务器配置,可能是主配置文件(/etc/apache2/apache2.conf,可能;这是Debian及其派生的默认值,而Rat Head系列中常见/etc/httpd/httpd.conf)或配置您正在查看其日志的虚拟主机的文件(对于Debian和公司来说是/etc/apache2/sites-enabled/*,上帝只知道Rat Head的位置)。

您所使用的配置指令可以是LogFormat,它将格式字符串别名为短名称,或CustomLog,它使用格式字符串或前面定义的短名称。一个LogFormat指令,用于指定实际的日志记录格式。

格式字符串语法详细in the Apache documentation

为了节省您一些时间,从眼球采样线和具有相当丰富的Apache日志经验,大多数格式似乎是:

<datetime> - "<request method> <url> <HTTP version>" <response status> <response length> <client address> "<request Referer: header value?>" "<request User-Agent: header value>" - ?? <response duration in microseconds?> - <newline>

我不知道涉及问号的部分是什么,但其余部分似乎很明显。