Apache, use X-Forwarded-For for allow

How can use X-Forwarded-For headers(my proxy ip 10.1.1.x) to allow HTTP query?


Solution 1:

You can use SetEnvIf and Allow:

    <Location "/only_proxy/">
            SetEnvIf X-Forwarded-For ^10\.1\.1\. proxy_env
            Order allow,deny
            Satisfy Any
            Allow from env=proxy_env
    </Location>

Solution 2:

You can write a rewrite rule to redirect to 403 response.

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-For} !(1.1.1.1|2.2.2.2)
RewriteRule .* - [F]

Solution 3:

You can use mod_rpaf to make Apache treat the X-Forwarded-For IP as the client IP.