You are not authorized to view comments.

When using mod_proxy, how can I make Tomcat log the client's IP address?

In your Apache HTTPD config, where you're configuring proxying the request, make sure you add: ProxyVia On This will make HTTPD set the "x-forwarded-for" HTTP request header's value to the IP address of the client. This value is passed to Tomcat when HTTPD proxies the request.

Then, where you're configuring the AccessLogValve (usually in your conf/server.xml file), change the default logging pattern to log the "x-forwarded-for" header value, like this:

<Host ...>
    <Valve className="org.apache.catalina.valves.AccessLogValve"
           directory="logs"
           prefix="localhost_access_log."
           suffix=".txt"
           pattern="%{x-forwarded-for}i %l %u %t %r %s %b"
           resolveHosts="false"/>
</Host>

With this configuration, AccessLogValve will log the x-forwarded-for header value that is set by Apache HTTPD's mod_proxy, and the remainder of the logging pattern will be the same as usual.



Tcat - Enterprise Tomcat Server

Tcat makes Apache Tomcat enterprise-ready. It provides centralized management and monitoring across all your Tomcat Servers. Built atop 100% Apache Tomcat, it provides all the enterprise capabilities you need for production deployment with zero rip and replace.
Apache Tomcat - Tcat Screenshot