Tomcat – How to get real IP (not 127.0.0.1) to show up as remote IP when forwarding requests in httpd

httpdtomcat

I've got a httpd server sitting in front of tomcat. Both services are running on the same machine.

The machine has 2 IP address and I have domain names that are bound to the different IPs.

In the access logs for tomcat all the remote IP addresses show 127.0.0.1. I think this is because all tomcat knows is that the request originated from a client identifying itself with IP 127.0.0.1 and that this client is actually Apache.

Is there any way to get Apache to identify itself with the actual IP the domain name is bound to?

EDIT : A slightly longer story…

What I'm actually trying to do is determine whether requests are coming from our internal network or from the internet. We have 2 host names which resolve to 2 different IP addresses. One of these addresses is visible from the internet and one is not. My hope was that I could determine which IP/URL the user actually typed into their browser and use this to disable certain features we do not want accessible from outside the intranet.

Cheers,
Peter

Best Answer

Tomcat needs to support the X-Forwarded-For header (Apache does that with the rpaf module), and httpd (Apache, I guess) needs to set that header for you.

BTW, if using a proxy, aren't you better off using Nginx?