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.

https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html

On Ubuntu/Debian, this can be enabled with command

Now create file

Add

IP_OF_YOUR_PROXY_SERVER_HERE = repace with your proxy server. This can be any proxy server like haproxy, nginx, etc..

Enable config with

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

On Ubuntu

Find

Replace with

Restart Apache with

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