LAMP--Apache 日志记录代理 ip 和真实客户端 ip

     默认的log日志格式在主配置文件 httpd.conf 中能够看到:前端

[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

     其中 %h 是记录访问者的 IP,若是在 web 的前端有一层代理,那么这个 %h 其实就是代理机器的 IP,这不是咱们想要的。在这种状况下,%{X-FORWARDED-FOR}i 字段会记录客户端真实的ip。因此配置文件改成:
web

    LogFormat "%h %{X-FORWARDED-FOR}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
相关文章
相关标签/搜索