apache and tomcat get remote ip

apache, java, tomcat7

Solution

You can use Remote_IP_Valve to set the actual IP address in the request.

In your tomcat/conf/server.xml add the valve like

<Valve className="org.apache.catalina.valves.RemoteIpValve"
   remoteIpHeader="x-forwarded-for"
/>

Problem

I have this setting in my apache, this work fine, but in my app when a get remote address this return local IP (127.0.0.1), how I solve this problem? ``` </Location> </VirtualHost><VirtualHost *:80> ServerName yourapp.yourdomain.com ServerAlias yourapp.* ProxyRequests Off ProxyPreserveHost On <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /webapp http://localhost:8080/webapp ProxyPassReverse /webapp http://localhost:8080/webapp <Location /webapp> Order allow,deny Allow from all </Location> </VirtualHost> ```

Original source