Cloudflare Restoring original visitor IPs with mod_remoteip in CWP/Apache

by Sandeep B.

In this tutorial we’ll going to learn how to configure Apache mod_remoteip in order to restore original ip when using cloudflare proxy. We’ve another blog post upon how we can configure mod_cloudflare to restore ip which for some are not at all working. This is the method which is working and recommended in cloudflare website.

So without wasting time lets get started with this simple steps. :

Step 1 :

Enabling mod_remoteip in Apache config :

sed -i '/LoadModule remoteip_module modules/ s/^#//g' /usr/local/apache/conf/httpd.conf  

Step 2 :

Now we’re going to configure cloudflare original ip config :

first of all create a file named “cloudflare.conf” in /usr/local/apache/conf.d

cd /usr/local/apache/conf.d
nano cloudflare.conf

then copy paste below config and save it :

#LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
RemoteIPHeader CF-Connecting-IP
RemoteIPTrustedProxy 173.245.48.0/20
RemoteIPTrustedProxy 103.21.244.0/22
RemoteIPTrustedProxy 103.22.200.0/22
RemoteIPTrustedProxy 103.31.4.0/22
RemoteIPTrustedProxy 141.101.64.0/18
RemoteIPTrustedProxy 108.162.192.0/18
RemoteIPTrustedProxy 190.93.240.0/20
RemoteIPTrustedProxy 188.114.96.0/20
RemoteIPTrustedProxy 197.234.240.0/22
RemoteIPTrustedProxy 198.41.128.0/17
RemoteIPTrustedProxy 162.158.0.0/15
RemoteIPTrustedProxy 104.16.0.0/12
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 131.0.72.0/22
RemoteIPTrustedProxy 2400:cb00::/32
RemoteIPTrustedProxy 2606:4700::/32
RemoteIPTrustedProxy 2803:f800::/32
RemoteIPTrustedProxy 2405:b500::/32
RemoteIPTrustedProxy 2405:8100::/32
RemoteIPTrustedProxy 2a06:98c0::/29
RemoteIPTrustedProxy 2c0f:f248::/32

*you can remove “#” uncomment from in front of LogFormat for customized log format.

Step 3 :

Restart Apache webserver and done :

systemctl restart httpd

or

service apache restart

If this post helps you in any way please consider a donation

Donate with PayPal :

md-donate

You may also like

7 comments

joe November 30, 2020 - 8:33 am

me podrian indicar como hacer lo mismo pero en un servidor ubuntu 18.04 administrado con plesk oxidian

GOOGLE TRANSLATED
Could you tell me how to do the same but on an ubuntu 18.04 server managed with plesk oxidian”

Reply
joe November 30, 2020 - 8:52 am

You could tell me how to do the same, but on an Ubuntu 18.04 server managed with plesk oxidian since I can’t get the real ip of the visitors

Reply
Sandeep B. November 30, 2020 - 5:44 pm

you need to enable mod_remoteip the use the cloudflare config under apache conf folder. Or search for cloudflare app if there is any available in plesk store.

Reply
joe November 30, 2020 - 6:38 pm

Good morning, thank you for answering: I want to tell you, activate the module with the command sudo a2enmod remoteip until there is good and perform all the steps described in the following link from cloudflare LINK but does not solve the visitor’s ip it keeps showing cloudflare ips I don’t know if it does it wrong or if it no longer works what they say on the cloudflare website. i was looking in plesk and there is no app for cloudflare. I know you have knowledge and could help me. I don’t know if you could have a tutorial like the one you show on this page but for Ubuntu 18.04 in advance I appreciate your time and attention

Reply
Sandeep B. November 30, 2020 - 8:21 pm

okay will look into it.

Reply
joe December 1, 2020 - 1:38 am

Thank you very much for answering SANDEEP B. I am waiting

Reply

Leave a Comment