【问题标题】:Can't get an Apache CustomLog to work无法让 Apache CustomLog 工作
【发布时间】:2017-06-29 21:28:46
【问题描述】:

我正在尝试为我的 httpd.conf 文件创建一个 CustomLog 指令。我插入的指令是

LogFormat "%h %t %t %{Referer}i" testx
CustomLog /var/www/httpd-logs/example.com.access.log testx

我有两次 %t,所以如果它通过,我可以更容易地看到日志条目。但事实并非如此。我在日志中看到的只是一行开头的“testx”,没有其他数据。

此外,我注意到 Apache 日志记录的文档在 %{Refered}i 周围加上引号,但如果我这样做,就像

LogFormat "%h %t %t "%{Referer}i"" testx 

ISP 管理器不会接受它进入 httpd.conf。

最后,我真正想要记录的是标头 Accept 值 (HTTP_ACCEPT),所以我尝试制作 LogFormat 行

LogFormat "%h %t %t %{Accept}i" testx

但这也不起作用。

有人看到我在这里做错了吗?谢谢。

【问题讨论】:

    标签: apache


    【解决方案1】:

    首先,如果你想在其中包含双引号,你必须将它们转义,如下所示:

    LogFormat "%h %t %t \"%{Referer}i\"" testx
    

    也就是说,你的例子对我来说很好:

    LogFormat "%h %t %t %{Referer}i" testx
    CustomLog /example/path/example.com.access.log testx
    

    给我(所有被禁止的条目只是访问我的测试站点的主页):

    1.2.3.4 [29/Jun/2017:23:25:20 +0000] [29/Jun/2017:23:25:20 +0000] -
    1.2.3.4 [29/Jun/2017:23:25:20 +0000] [29/Jun/2017:23:25:20 +0000] http://www.example.com/
    1.2.3.4 [29/Jun/2017:23:25:20 +0000] [29/Jun/2017:23:25:20 +0000] -
    1.2.3.4 [29/Jun/2017:23:25:20 +0000] [29/Jun/2017:23:25:20 +0000] -
    1.2.3.4 [29/Jun/2017:23:25:22 +0000] [29/Jun/2017:23:25:22 +0000] -
    1.2.3.4 [29/Jun/2017:23:25:23 +0000] [29/Jun/2017:23:25:23 +0000] http://www.example.com/
    

    确保您没有将它们添加到 .htaccess 文件中,并且不要忘记在进行更改后重新启动 Apache。

    【讨论】:

      猜你喜欢
      • 2010-10-06
      • 1970-01-01
      • 2014-09-02
      • 2012-04-27
      • 1970-01-01
      • 2012-05-10
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多