Skip to content

Restoring real visitor IPs on cPanel Apache with mod_remoteip

Apache logs full of Cloudflare IPs break stats, bans, and WordPress security plugins. Install mod_remoteip through EasyApache 4 and trust CF-Connecting-IP from Cloudflare ranges only.

Once a domain is proxied, every connection Apache sees comes from a Cloudflare edge IP: access logs, AWStats, .htaccess IP allow rules, PHP’s REMOTE_ADDR, WordPress login throttles — all of them now watch Cloudflare instead of visitors. On a stock cPanel server (Apache via EasyApache 4), the fix is mod_remoteip: it swaps the connection IP for the value of the CF-Connecting-IP header, but only when the connection comes from an IP range you have explicitly told it to trust. Install the EA4 package, add the directives through WHM’s Include Editor, restart Apache — twenty minutes including verification.

What’s happening

The proxied request arrives at your origin over a TCP connection from Cloudflare, so the peer address genuinely is a Cloudflare IP. The real client address rides inside the request, in the CF-Connecting-IP header (with X-Forwarded-For alongside for compatibility). Nothing on the origin reads that header by default.

mod_remoteip rewrites Apache’s idea of the client address early in request processing, so everything downstream — logging, ModSecurity, PHP, per-directory access control — sees the restored visitor IP. The critical safety property is the trusted-proxy list: the header is only honoured when the actual connection IP matches RemoteIPTrustedProxy. Without that restriction, anyone connecting directly to the origin could send a forged CF-Connecting-IP header and impersonate any address — which is exactly what naive header-trusting configurations allow.

One nuance worth knowing on mixed servers: if only some domains are proxied, the module is still safe. Requests arriving directly (not from a trusted range) keep their genuine connection IP; only connections from Cloudflare ranges get rewritten.

What to check first

Confirm the symptom is what it looks like — logs dominated by a handful of repeating ranges — and confirm which web server is actually in front. Also worth knowing before you start: everything that reads Apache’s view of the client downstream — AWStats, Webalizer, bandwidth accounting, log-driven ban tooling — inherits the fix automatically once the module rewrites the address, so there is nothing to reconfigure in those layers afterwards. This article is the Apache default stack; if the server runs the Nginx reverse-proxy setup, use real visitor IPs behind Cloudflare on Nginx instead, and on LiteSpeed the equivalent is its own “Use Client IP in Header” setting, not an Apache module.

How to verify

# Is mod_remoteip loaded?
apachectl -M | grep remoteip

# What do the domain logs record right now?
tail -200 /etc/apache2/logs/domlogs/example.com | awk '{print $1}' | sort | uniq -c | sort -rn | head

No remoteip_module line and a log dominated by ranges like 172.68.x.x or 104.2x.x.x confirms the diagnosis. After the fix, the same two commands are the proof: the module listed, and the log showing diverse real addresses.

The fix

  1. Install the module. In WHM » Software » EasyApache 4 » Currently Installed Packages » Customize » Apache Modules, enable mod_remoteip and provision. Command-line equivalent: yum install ea-apache24-mod_remoteip (or dnf on newer systems).
  2. Add the configuration where EasyApache will not overwrite it. In WHM » Service Configuration » Apache Configuration » Include Editor » Pre Main Include » All Versions, 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/13
RemoteIPTrustedProxy 104.24.0.0/14
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
  1. Restart Apache. /scripts/restartsrv_httpd, then re-run the verification commands. New log lines should show visitor addresses.
  2. Confirm the application layer agrees. A quick PHP page printing REMOTE_ADDR, or a WordPress security plugin’s dashboard, should now show real client IPs. ModSecurity also keys on the restored address from here on, which is half the cure for ModSecurity false positives behind Cloudflare.
  3. Keep the ranges current. The list changes rarely, but it does change. The authoritative source is cloudflare.com/ips; a quarterly calendar entry to diff the published list against your include file is enough discipline for most fleets. If you script the refresh, regenerate the include from https://www.cloudflare.com/ips-v4 and ips-v6 and do a graceful restart.

When this fix is wrong

If the server sits behind another layer in addition to Cloudflare — a local Nginx front, a load balancer — the trusted-proxy chain has to reflect the directly connecting hop, and RemoteIPInternalProxy for the private hop may be needed; blindly trusting Cloudflare ranges that never actually connect to Apache does nothing. If logs show Cloudflare IPs only for some vhosts, those domains may be proxied while others are not — that is expected, not a bug. And do not use this module to “fix” mail or panel logs: Exim and cpsrvd never see the header, because their traffic does not pass through Cloudflare at all.

Common mistakes

Using X-Forwarded-For as the trusted header — it is client-appendable and ambiguous through multi-hop chains; CF-Connecting-IP is the one Cloudflare sets authoritatively. Omitting the IPv6 ranges, then chasing “some visitors still show as Cloudflare.” Editing httpd.conf directly, which an EasyApache rebuild silently reverts — the Include Editor exists precisely for this. Trusting the header from everywhere (0.0.0.0/0), which converts your logs into attacker-controlled fiction. Forgetting the restart and declaring the module broken.

Prevention

Bake the module and the include into the server provisioning template so every new cPanel box ships with it, and pair it with the firewall-side allowlist so the two Cloudflare range lists are refreshed together — the CSF half is covered in allowlisting Cloudflare IP ranges in CSF and LFD.

Running Cloudflare in front of cPanel/WHM is a stack Stack Harbor operates daily as an official cPanel NOC partner — cPanel server management covers the DNS, mail, SSL, and firewall plumbing, and you can start a conversation any time.