Show X-Forwarded-For IP in Apache

When apache is running behing proxy server it shows IP of proxy server as visitor IP. To fix this, you need to enable Apache module remoteip.

On Ubuntu/Debian, this can be enabled with command

Now create file


IP_OF_YOUR_PROXY_SERVER_HERE = repace with your proxy server. This can be any proxy server like haproxy, nginx, etc.. If you have more than one proxy server, use IPs seperated by space.

Enable config with

To get Apache Logs show real Visitor IP, replace %h with %a in LogFormat.

On Ubuntu


Replace with

Restart Apache with

Now apache/php will show proper visitor IP instead of proxy server IP.

Leave a Reply

Your email address will not be published. Required fields are marked *