Cloudflare Restore Real IP Address in Cpanel Server

When using Cloudflare, website visitors visit the Cloudflare CDN server configured as a reverse proxy server. Cloudflare CDN server fetches pages from your web server and caches them for a while, serving them to subsequent visitors. Your web application may report Cloudflare CDN server IP ad visitor IP as all requests to your website are coming from Cloudflare CDN. This can be a problem when you have an e-commerce website where you need to check visitor IPs to detect fraud signups/orders.

To restore the original visitor IP for visitors on cPanel Server running the Apache web server, you can use mod_remoteip. You can install mod_remoteip in WHM > EasyApache 4 > Apache Modules

enable mod_remoteip in cpanel EasyApache

You can also install mod_remoteip using command line

dnf install ea-apache24-mod_remoteip

Login to SSH as user root or WHM > Terminal, then edit the file

vi /etc/apache2/conf.modules.d/370_mod_remoteip.conf 

At end of the file, add

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 find Cloudflare IP address at

https://www.cloudflare.com/ips/

Restart Apache

systemctl restart httpd

Back to Cloudflare

Comments

Leave a Reply

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