Score:0

How to get HTTP_X_FORWARDED_FOR in Apache config files

us flag

I have a protected admin area that is only accessible for my IP. However, I am using a proxy that has a lot of IPs. It's not practical to whitelist all its list of IPs.

The proxy sends the HTTP_X_FORWARDED_FOR header that contains the real IP.

I can get that information in PHP with $_SERVER['HTTP_X_FORWARDED_FOR'].

My objective is to whitelist that IP contained in "HTTP_X_FORWARDED_FOR" if it equals my own IP.

Here’s the code I want to set in my Apache config file:

# The value is hardcoded and will be edited if my real IP is changed.
DEFINE myRealIp "XXX.XXX.XXX.XXX"

# That's what I am looking for.
DEFINE originIpFromProxy variable_method_to_get_that_value

<LocationMatch "/admin/">
    Order deny,allow
    Deny from all

    <If "'${originIpFromProxy}' == '${myRealIp}'">
        Allow from ${originIpFromProxy}
    </If>
</LocationMatch>

There's also a problem, the header HTTP_X_FORWARDED_FOR may contain many IPs separated with commas.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.