Gustavo Rozolin Gustavo Rozolin - 11 months ago 175
Apache Configuration Question

apache and tomcat get remote ip

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>

Answer Source

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"
/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download