Nginx – Blocking IP’s Nginx behind proxy

nginxPHPPROXY

I'm running a Nginx 1.2.4 webserver here, and I'm behind a proxy of my hoster to prevent ddos attacks. The downside of being behind this proxy is that I need to get the REAL IP information from an extra header. In PHP it works great by doing $_SERVER[HTTP_X_REAL_IP] for example.

Now before I was behind this proxy of my hoster I had a very effective way of blocking certain IP's by doing this: include /etc/nginx/block.conf and to allow/deny IP's there.

But now due to the proxy, Nginx sees all traffic coming from 1 IP.

Is there a way I can get Nginx to read the IP's like how PHP does, with the X-REAL-IP header?

Best Answer

Usually proxy servers send an header X_FORWARDED_FOR containing clients real ip address. You can use --with-http_realip_module to get the real ip address. Here is module's page