Apache LogFormat 和 CustomLog

Apache LogFormat 和 CustomLog

我正在阅读一本关于 Logstash 的书,作者提供了一个示例 conf 文件。我正在运行安装了 Apache 2 的 Ubuntu 16.04 服务器。我将 conf 文件添加到 /etc/apache2/conf-available 并使用 a2enconf 创建指向 conf-enabled 的符号链接。我在 /var/log/apache2/ 中看到了新的日志文件,但日志文件中没有添加任何内容。我已匹配此目录中其他日志文件的权限。任何建议都将不胜感激。以下是我的 conf 文件:

LogFormat "{ \
\"host\":\"webapp.local\", \
\"path\":\"/var/log/apache2/logstash_access_log\", \
\"tags\":[\"wordpress\",\"www.example.com\"], \
\"message\": \"%h %l %u %t \\"%r\\" %>s %b\", \
\"timestamp\": \"%{%Y-%m-%dT%H:%M:%S%z}t\", \
\"clientip\": \"%a\", \
\"duration\": %D, \
\"status\": %>s, \
\"request\": \"%U%q\", \
\"urlpath\": \"%U\", \
\"urlquery\": \"%q\", \
\"method\": \"%m\", \
\"bytes\": %B, \
\"vhost\": \"%v\" \
}" logstash_apache_json

CustomLog /var/log/apache2/logstash_access_log logstash_apache_json

答案1

希望这对其他人有所帮助。原始帖子来自https://stackoverflow.com/questions/525057/why-cant-i-get-apaches-customlog-directive-to-work

解决方法 1

如果您已在单独的配置文件中设置 CustomLog 指令,请从配置文件中删除它。将 CustomLog 指令添加到站点的 VirtualHost 条目中。对我来说,这是在 /etc/apache2/sites-available/default-ssl 中,因为我只允许 SSL 访问 Subversion 存储库。如果您使用的是 /etc/apache2/sites-available/default,则需要编辑该文件(或者如果您同时使用两者,则除了 default-ssl 之外还要编辑该文件)。重新启动 Apache:sudo /etc/init.d/apache2 restart

专业版

您可以在站点的 VirtualHost 条目中拥有多个 CustomLog 指令,并且它们都可以起作用。

反对意见

您必须将 CustomLog 条目移到站点的 VirtualHost 条目中,而不是将其放在单独的配置文件中。

解决方法 2

注释掉您站点的 VirtualHost 条目中的 CustomLog 指令。如果您使用的是默认站点配置之一(默认或默认 SSL),则将有一个用于访问日志的 CustomLog 指令,您需要将其注释掉(是的,这会关闭 Apache 的默认访问日志记录)。将您的 CustomLog 指令添加到相应的配置文件中。对我来说,这是 /etc/apache2/mods-available/dav_svn.conf。重新启动 Apache:sudo /etc/init.d/apache2 restart

专业版

您可以将 CustomLog 指令保存在单独的配置文件中。

反对意见

这种解决方法的明显缺点是您必须禁用 Apache 的默认访问日志记录,但对我来说,我不太在意,因为我只使用服务器进行 Subversion 访问。

结论

这两种解决方法都不是理想的,但到目前为止,除了上述两种解决方法之外,我还没有找到其他方法。我想我们必须等到 Apache 的下一个版本才能解决这个问题。

相关内容