2007
01.08

默认在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地址

7 comments so far

Add Your Comment
  1. 不错的小经验,感谢楼主!

  2. flying on August 27, 2007 at 10:55 am  

    (Quote)
    said:

    或者,如果是cdn服务器,既有通过squid过来的访问,也有直接从用户过来的访问,可怎么弄啊

    这样的情况下,基本上都是收集squid的日志进行统计分析,而不是分析后端日志了。

  3. suchasplus on October 15, 2008 at 4:02 pm  

    (Quote)
    said:

    呵呵
    楼主的方法不错
    不过还有一个官方方法,不需要修改accesslog.format
    启用m…

    严格来说, X-Forwarded-For header的值不能完全信任..Lighttpd的extforword可以限定来源地址,对非信任地址直接记录成127.0.0.1
    当初测试端口转发的时候发现sina的后端apache都限定了来源地址,必须从前端squid走

  4. 谢谢,说得很好 :)

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word