【问题标题】:No IP address in apache logsapache日志中没有IP地址
【发布时间】:2019-07-08 22:08:59
【问题描述】:

我有一个在 CentOS 6.5 服务器上运行的 apache 服务器。在日志文件中 25% 的记录是这样的

000.000.000.000 - - [24/Jul/2014:04:15:10 +0000] "GET /address/of/the/page.html HTTP/1.1" 200 20341 "-" "Mozilla/4.0 

但是其余75%的日志都是这样的,没有IP

- - [24/Jul/2014:04:15:10 +0000] "GET /address/of/the/page.html HTTP/1.1" 200 20341 "-" "Mozilla/4.0

谁能告诉我是什么问题? 谢谢!

【问题讨论】:

    标签: linux apache logging centos


    【解决方案1】:

    默认情况下,Apache 在访问日志中打印 REMOTE_ADDR 标头值,在您的环境中,在某些情况下该值可能为空。您可以尝试在访问日志中打印 X-Forwarded-For 标头,看看是否有您需要的值。

    通常,如果请求通过代理服务器/负载平衡器传递,最好检查 XFF 标头的值以获取正确的客户端 IP。

    希望对您有所帮助。

    -Avijit

    【讨论】:

    • 你能给我一些关于访问 X-Forwarded-For 标头的详细信息吗?
    • %{X-Forwarded-For}i 您可以将其添加到 httpd.conf 中的自定义日志格式指令中。
    【解决方案2】:

    补充 Avi 的响应,您需要打开文件 /etc/apache2/apache2.conf 并更改以下行:

    LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined

    LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" 组合

    LogFormat "%h %l %u %t \"%r\" %>s %O" 常用

    LogFormat "%{Referer}i -> %U" 引用者

    LogFormat "%{User-agent}i" 代理

    到:

    LogFormat "%{X-Forwarded-For}i %v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"% {User-Agent}i\"" vhost_combined

    LogFormat "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent} i\"" 合并

    LogFormat "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %O" common

    LogFormat "%{X-Forwarded-For}i %{Referer}i -> %U" 引用者

    LogFormat "%{X-Forwarded-For}i %{User-agent}i" 代理

    然后,使用以下命令重新启动 apache 服务:sudo service apache2 restart 并且客户端 ip 将出现在 apache 日志中。 检查结果: cat /var/log/apache2/access.log

    【讨论】:

      猜你喜欢
      • 2015-05-30
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-18
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      相关资源
      最近更新 更多