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
  2. James said on 2021-05-13, 12:40
    FYI for others that might run into this. I spent a while trying to figure out why X-Forwarded-For was empty in nginx. It slipped my mind that since I'm using end-to-end SSL with my own cert on the web server, PageKite can't modify the headers to add X-Forwarded-For, so this won't work for end to end encryption.
    Permalink

Leave a comment

( (Please leave these blank: )

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