I am trying to log website visitor application in tomcat logs I have tried adding below lines of code in server.xml
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%{X-Forwarded-For}i %h %F %l %u %t "%r" %s %b"/>
I am getting the below output in the tomcat log.
- 192.168.1.149 15 - - [24/Jul/2020:16:24:16 +0200] "GET /geonetwork/srv/eng/shib.user.login.noforward HTTP/1.0" 200 50
I need to get remote IP of one who is accessing the application
There are 2 scenario, your tomcat is not behind any load balancer or proxy or behind one. If your tomcat is not behind proxy or load balancer, it's already correct. For more precaution, maybe add
%a
so it can grab the remote ip address as stated in Access_Log_ValveTo
If you want to use
%h
for Remote host name, please set enableLookups="true" at connectorBut in any case that the tomcat is behind proxy or load balancer, add more configuration like this:
The proxy default ip addresses that used by RemoteIpValve:
And maybe if your proxy is not listed here, add internalproxies configuration to catch the proxy: