Edit Apache configuration file

vi /etc/httpd/conf.d/remoteip.conf

Add

RemoteIPHeader X-Forwarded-ForRemoteIPTrustedProxy IP_OF_YOUR_PROXY_SERVER_HERE

Example

[root@localhost ~]# cat  /etc/httpd/conf.d/remoteip.confRemoteIPHeader X-Forwarded-ForRemoteIPTrustedProxy 192.168.122.1[root@localhost ~]#

Doing this will make PHP scripts show real IP of visitor. You need to restart Apache web server before the change take effect. You can verify by creating a PHP script with content

	
<?php echo $_SERVER["REMOTE_ADDR"];

To make Apache show real IP in access log, edit

vi /etc/httpd/conf/httpd.conf

Find

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

Replace with

LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

Restart Apache web server

Centos / Redhat :

systemctl restart httpd

Ubuntu :

systemctl restart apache2

Leave a Reply

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