haproxy,tomcat.apache记录用户真实IP

Haproxy配置:

default加入:

option httpclose

option forwardfor

Tomcat配置:

server.xml中添加

  • prefix="localhost_access_log." suffix=".txt"
  • pattern="%{X-FORWARDED-FOR}i %l %u %t %r %s %b %D %q %{User-Agent}i %T" resolveHosts="false"/>完整配置为:
  • <Valve className="org.apache.catalina.valves.AccessLogValve"

                    directory="logs" 

                    prefix="localhost_access_log."

                    suffix=".txt"

                    pattern="%{X-FORWARDED-FOR}i %l %u %t %r %s %b %D %q %{User-Agent}i %T"

                    resolveHosts="false"/>

    Apche配置:

    <IfModule log_config_module>

        LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

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

        <IfModule logio_module>

          LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

        </IfModule>

        CustomLog "logs/access_log" common

    </IfModule>

    posted @ 2015-11-25 23:02  我是一条最咸的咸鱼  阅读(1393)  评论(0编辑  收藏  举报
    返回顶部