the fast, reliable localhost tunneling solution


Logging client IPs in Apache

By Bjarni RĂșnar Einarsson 2011-07-02, 09:28

PageKite is a reverse proxy server, which means when it forwards connections to Apache, the default Apache logs will by default only ever record 127.0.0.1 as the client.

However, PageKite does attempt to add the X-Forwarded-For HTTP header to requests whenever possible. Apache can be configured to record that value in the log-files instead of 127.0.0.1.

To enable this, add a stanza similar to the following to your site configuration:

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" f5_forwarder
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" is-forwarded
CustomLog ${APACHE_LOG_DIR}/access.log combined env=!is-forwarded
CustomLog ${APACHE_LOG_DIR}/access.log f5_forwarder env=is-forwarded

These directives should be placed inside a VirtualHost block.

(this snippet is based on code found here).

Comments

  1. Thomas Tanghus said on 2013-09-04, 20:18
    Excellent - just what I was looking for :)
    Permalink

Leave a comment

( (Please leave these blank: )

We use Gravatar for commenter's photos. Get your own, it's free!

Wiki

Links