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

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

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
7 Responses
  1. 喜欢BSD says:

    不错的小经验,感谢楼主!

  2. flying says:

    如果是一层以上代理可怎么办呀?

  3. flying says:

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

  4. Michael says:

    [Comment ID #18069 Will Be Quoted Here]

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

  5. suchasplus says:

    呵呵
    楼主的方法不错
    不过还有一个官方方法,不需要修改accesslog.format
    启用mod_extforward即可
    mod_extforward – extract the client’s “real” IP from X-Forwarded-For header
    http://redmine.lighttpd.net/wiki/lighttpd/Docs#Options-for-mod_extforward-extract-the-clients-real-IP-from-X-Forwarded-For-header
    btw:lighttpd什么时候抛弃trac了???

  6. suchasplus says:

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

  7. Michael says:

    谢谢,说得很好 🙂

  8. minecraft says:

    Hmm is anyone else encountering problems with the pictures on this blog loading?

    I’m trying to figure out if its a problem on my end or if it’s the blog.
    Any responses would be greatly appreciated.

  9. minecraft says:

    If you wish for to obtain much from this article then you have
    to apply these strategies to your won web site.

  10. Awesome! Its truly awesome piece of writing, I have got much clear idea on the topic of from this article.

  11. Usually I do not read post on blogs, but I wish to say that this
    write-up very compelled me to try and do it! Your writing taste has been amazed me.
    Thank you, very nice post.

  12. What’s up, yes this post is actually good
    and I have learned lot of things from it about blogging. thanks.

  13. Peculiar article, totally what I was looking for.

  14. Hi would you mind sharing which blog platform you’re using?
    I’m planning to start my own blog soon but I’m having a
    hard time deciding between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most blogs and I’m looking for something completely unique.
    P.S My apologies for being off-topic but I had to ask!

  15. If you are going for best contents like me, just pay
    a quick visit this website every day since it presents quality
    contents, thanks

  16. I would like to thank you for the efforts you’ve put in writing this website.
    I’m hoping to view the same high-grade blog
    posts by you later on as well. In truth, your creative writing abilities
    has inspired me to get my own, personal site now 😉

  17. Awesome website you have here but I was curious if you knew of any discussion boards that
    cover the same topics talked about here? I’d really love to be a
    part of online community where I can get advice from other knowledgeable individuals that
    share the same interest. If you have any recommendations, please let me know.
    Thank you!

  18. Thanks on your marvelous posting! I truly enjoyed reading it, you
    might be a great author. I will make sure to bookmark your blog and may come
    back at some point. I want to encourage you to ultimately continue your great writing, have a nice morning!

  19. What i do not realize is in truth how you are no longer actually much more neatly-liked
    than you might be now. You’re so intelligent.
    You recognize therefore considerably when it
    comes to this matter, made me individually imagine it from numerous various angles.
    Its like women and men are not involved unless it is one thing to do
    with Girl gaga! Your individual stuffs nice.
    Always maintain it up!

  20. After looking into a few of the blog articles on your site, I truly appreciate your way of blogging.
    I saved it to my bookmark site list and will be checking back soon. Please check out my
    web site too and tell me how you feel.

  21. Sling TV says:

    I really like your blog.. very nice colors & theme.
    Did you create this website yourself or did you hire someone to
    do it for you? Plz answer back as I’m looking to design my own blog and would like to
    know where u got this from. thanks a lot

  22. Sling TV says:

    Excellent pieces. Keep posting such kind of info on your blog.
    Im really impressed by it.
    Hi there, You have done a fantastic job. I’ll definitely digg it and individually suggest to
    my friends. I’m sure they’ll be benefited from this website.

  23. Hi, i think that i saw you visited my site so i came to “return the favor”.I’m trying to find things to enhance my
    web site!I suppose its ok to use a few of your
    ideas!!

  24. What’s Taking place i am new to this, I stumbled
    upon this I have discovered It absolutely useful and it has aided me
    out loads. I hope to give a contribution & aid different
    users like its helped me. Great job.

  25. sling tv coupons and promo codes for november 2018
    It’s difficult to find knowledgeable people on this subject, however,
    you sound like you know what you’re talking about! Thanks sling tv coupons and promo codes for november 2018

  26. Write more, thats all I have to say. Literally, it seems as though you relied
    on the video to make your point. You obviously know what youre talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?

  27. Very descriptive post, I loved that bit. Will
    there be a part 2?

  28. It’s very easy to find out any matter on web as compared to books, as I found
    this post at this web page.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
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.
Anti-spam image