Search code examples
apacheproxyipforwardingvisitor-pattern

Real IP behind Apache Load Balancer (Proxy) Server


I need to forward the real ip of the visitor to Apache Load Balancer. I have done it on Nginx successfully by just adding following two lines:

proxy_set_header    X-Real-IP        $remote_addr;
proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for

I also have found above solution (for Nginx) on websites that explain the solution for both Apache and Nginx, but it doesn’t work for Apache. Generally solutions are shared for Apache Servers as a back-end server. However, in my case, Apache is the load balancer. I have also tried mod_rpaf but either it did not work or I couldn’t apply it successfully.


Solution

  • 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.

    https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#x-headers