squid后面的lighttpd、apache,jetty日志记录用户ip的方法

来源:互联网 发布:java解析xml 编辑:程序博客网 时间:2024/05/21 05:08




squid后面的日志记录用户ip的方法

squid.conf 中 打开ip转发
forwarded_for on

lighttpd:
默认在lighttpd的accesslog里面无法记录透过squid或者apache的 mod_proxy过来的用户ip地址,全都会记录到squid或者apache机器的ip地址,但是httpd头里面的用户ip其实是发送到 lighttpd的,可以通过修改accesslog.format来达到目的,下面是我的格式,跟combined兼容:
accesslog.format  = "%{X-Forwarded-For}i %v %u %t /"%r/" %s %b  /"%{User-Agent}i/" /"%{Referer}i/""

其中”%{X-Forwarded-For}i 就是记录了用户来源的ip地址

apache 修改方法:
LogFormat "%h %l %u %t /"%r/" %>s %b /"%{X-Forwarded-For}i/"" common
CustomLog "logs/access.log" common

jetty 5 修改:
<!-- =============================================================== -->
  <!-- Configure the Request Log                                       -->
  <!-- =============================================================== -->
  <Set name="RequestLog">
    <New class="org.mortbay.http.NCSARequestLog">
      <Arg><SystemProperty name="jetty.home" default="."/>/logs/yyyy_mm_dd.request.log</Arg>
      <Set name="retainDays">90</Set>
      <Set name="append">true</Set>
      <Set name="extended">false</Set>
      <Set name="LogTimeZone">GMT</Set>
      <Set name="PreferProxiedForAddress">true</Set>
    </New>
  </Set>