Blocking ips with .htaccess behind varnish

.htaccessapache-2.2varnish

I have the following issue. I have a normal apache/varnish installation on a server with 5 IPs and varnish sends each request to apache using the local IP (which i think is normal since in the backend I can get the referrer with php's $_SERVER['HTTP_X_FORWARDED_FOR'].

I cannot use though the .htaccess file's blocks since apache gets only the local IP. Everything I deny from inside .htaccess is never applied. If i go to port :81 (apache's port), the block works normally.

What I need to do is find a way to either block the IP from varnish itself or send back to apache the original referrer ID and all this without restarting varnish (Of course, if this is not possible, I will have to do so…)

That specific IP I want to block, is getting very suspicious……

Thank you all in advance

Best Answer

You should install mod_rpaf on your apache server. This will update the remote address with the last IP address from the X-Forwarded-For header. On debian based systems:

sudo apt-get install libapache2-mod-rpaf

then restart apache.