We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.


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"
           pattern="%{x-forwarded-for}i %l %u %t %r %s %b"

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.