Tomcat Logging - Logging X-Forwarded-For in Tomcat 6
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