2
votes

I have 2 Apache Http servers 2.4 as my load balancers for my Application. The issue that I am running into is that my application picks the remote host as one of the load balancer, but I actually want the real origin of the request, as in the client that initiated the call. Does someone know how to actually get the real remote host?

1

1 Answers

4
votes

From Apache 2.4 mod_proxy documentation:

When acting in a reverse-proxy mode (using the ProxyPass directive, for example), mod_proxy_http adds several request headers in order to pass information to the origin server. These headers are:

  • X-Forwarded-For The IP address of the client.

  • X-Forwarded-Host The original host requested by the client in the Host HTTP request header.

  • X-Forwarded-Server The hostname of the proxy server.

Be careful when using these headers on the origin server, since they will contain more than one (comma-separated) value if the original request already contained one of these headers. For example, you can use %{X-Forwarded-For}i in the log format string of the origin server to log the original clients IP address, but you may get more than one address if the request passes through several proxies.

So you actually need to catch the X-Forwarded-For HTTP header from your end application. But be careful, as the doc says, it may as well contain the IP addresses of all the intermediate proxies that are in front of your Apache proxy.