Set REMOTE_ADDR to X-Forwarded-For in apache

tylerl picture tylerl · Feb 11, 2010 · Viewed 52.6k times · Source

In a situation where Apache is sitting behind a reverse proxy (such as Squid), the cgi environment variable REMOTE_ADDR gets the address of the proxy rather than the client.

However, the proxy will set a header called X-Forwarded-For to contain the original IP address of the client so that Apache can see it.

The question is, how do we get Apache to replace REMOTE_ADDR with the value in the X-Forwarded-For header so that all of the web applications will transparently see the correct address?

Answer

maciekb picture maciekb · Aug 6, 2010

You can use mod_rpaf for that. http://stderr.net/apache/rpaf/