SOLVED Visitor IPs in Logs using cloudflare

domainerq

Member
Feb 22, 2017
14
5
3
Peru
cPanel Access Level
Root Administrator
Hello, i am trying to get in Cpanel log the real ip of my visitor, but for some reason, that's not working.

I have installed - CENTOS 6.8 x86_64 / WHM 62.0 / easyapache 4

Here the steps that i have done.

1. I installed whm from scratch.
2. I have added mod_ remoteip . (Also ,before i tried installing mod_cloudflare but there was several problems after the installation) , so i prefer not to use 3rd party modules.
3. i rebuilt easyapache 4.

4. i have added the code below , in /etc/apache2/conf/httpd.conf


<IfModule !mod_remoteip.c>
LoadModule remoteip_module modules/mod_remoteip.so
</IfModule>

<IfModule mod_remoteip.c>
# CloudFlare Header
RemoteIPHeader CF-Connecting-IP

# Trusted Proxy List
# note - using RemoteIPTrustedProxy instead of RemoteIPInternalProxy
# note - RemoteIPTrustedProxy does NOT trust Header provided private intranet addresses (local and LAN addresses)
# note - RemoteIPInternalProxy is a security risk when using an external Proxy

# CloudFlare IPv4 Address Ranges
RemoteIPTrustedProxy 103.21.244.0/22
RemoteIPTrustedProxy 103.22.200.0/22
RemoteIPTrustedProxy 103.31.4.0/22
RemoteIPTrustedProxy 104.16.0.0/12
RemoteIPTrustedProxy 108.162.192.0/18
RemoteIPTrustedProxy 141.101.64.0/18
RemoteIPTrustedProxy 162.158.0.0/15
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 173.245.48.0/20
RemoteIPTrustedProxy 188.114.96.0/20
RemoteIPTrustedProxy 190.93.240.0/20
RemoteIPTrustedProxy 197.234.240.0/22
RemoteIPTrustedProxy 198.41.128.0/17
RemoteIPTrustedProxy 199.27.128.0/21

# CloudFlare IPv6 Address Ranges
RemoteIPTrustedProxy 2400:cb00::/32
RemoteIPTrustedProxy 2405:8100::/32
RemoteIPTrustedProxy 2405:b500::/32
RemoteIPTrustedProxy 2606:4700::/32
RemoteIPTrustedProxy 2803:f800::/32
</IfModule>

5. I restarted httpd .
6. i have added in a php file.

if($_SERVER["HTTP_X_FORWARDED_FOR"]){
echo "Proxy ip : {$_SERVER['REMOTE_ADDR']}<br>";
echo "Real IP : {$_SERVER['HTTP_X_FORWARDED_FOR']}";
}else{
echo "Real IP: {$_SERVER['REMOTE_ADDR']}";}
?>

And the value of HTTP_X_FORWARDED_FOR it is the same than REMOTE_ADDR , so i can see my real ip in both of them, then I open the cpanel logs and this still shows the ip's cloudflare.

Is there something else that i have to do?

Thanks.
 
Last edited:
  • Like
Reactions: Del Drago

MohammadNehme

Member
Jul 23, 2022
11
2
3
Lebanon
cPanel Access Level
Root Administrator
@MohammadNehme - it might be best to create a new thread with your specific issue as this one is five years old.
Thank you for your reply , i managed to make it work at last. The only difference was that the code now should be added to the include file ( can be found in Service Configuration >>> Apache Configuration >>> include editor in the Pre Main Include (select all versions)