« Connecting IIS with Tomcat using isapi_redirect | Main | Java Code to Read the X-Forwarded-For Header »


Tomcat Logging - Logging X-Forwarded-For in Tomcat 6

I've consolidated this post and some others into a new HOWTO, plus added some new information. Check out HOWTO: Configure Access Logging in Tomcat from my Techstacks HOWTO site!

If you wish to get the client IP logged in your tomcat 6 container's access log and your tomcat container is sitting behind some kind of proxy like a BigIP LTM and/or mod_proxy on apache, then a quick modification of the Access Log valve is in order.

You will have to create a custom pattern so copy and paste your current Valve entry and then comment out the original.  Replace "pattern="common" or "pattern="combined" (depending upon the one you use or the one you want to use) with the following values:

Common:  %h %l %u %t "%r" %s %b
Combined:  %h %l %u %t %r %s %b %{User-Agent}i %{Referer}i

Once that is completed, then you will want to swap out the %h from the pattern and replace it with a %{X-Forwarded-For}i.  So, your updated patterns will now look like:

Common: %{X-Forwarded-For}i %l %u %t "%r" %s %b
Combined: %{X-Forwarded-For}i %l %u %t %r %s %b %{User-Agent}i %{Referer}i


TrackBack URL for this entry:

Listed below are links to weblogs that reference Tomcat Logging - Logging X-Forwarded-For in Tomcat 6: