Restore visitor IP addresses in Apache logs when requests arrive through a trusted reverse proxy. This article explains how to configure mod_remoteip on a cPanel & WHM server, distinguishing cPanel’s managed Cloudflare configuration from a custom proxy.

Before you start

You need root access and an EasyApache 4 configuration with mod_remoteip available. Record the existing configuration and log formats before changing them. Confirm the header sent by your proxy and its actual source IP addresses.

Check the Cloudflare configuration

Current cPanel versions create /etc/apache2/conf.d/includes/cloudflare.conf for Cloudflare’s CF-Connecting-IP header. If you use Cloudflare, check that managed configuration before adding a conflicting RemoteIPHeader directive.

For a custom proxy using X-Forwarded-For, follow the custom-proxy steps below. If the server hosts sites using both Cloudflare and other proxies, have the administrator review the combined configuration before disabling Cloudflare support globally.

Prepare a custom-proxy configuration

The following step disables cPanel’s managed Cloudflare configuration. Use it only when that is appropriate for the server’s proxy setup.

In a root SSH session, run cPanel’s documented preparation commands:

touch /var/cpanel/no_apache_cloudflare
/usr/local/cpanel/scripts/rebuildhttpdconf
/usr/local/cpanel/scripts/restartsrv_httpd

In WHM, open Service Configuration > Apache Configuration > Include Editor. Select Pre VirtualHost Include > Global. Alternatively, edit /etc/apache2/conf.d/includes/pre_virtualhost_global.conf as root.

Add the header and the verified address of your proxy. This example uses a documentation address; replace it with your actual proxy IP:

RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy 203.0.113.2

For a trusted internal proxy that must forward private client addresses, use RemoteIPInternalProxy with its verified address instead. Both directives support CIDR ranges. Do not copy example addresses or trust all sources.

Save the include. Do not place this custom configuration in the module loader file used by the older version of this article.

Update Apache log formats

Open WHM > Service Configuration > Apache Configuration > Global Configuration.

Set LogFormat (combined) to:

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

Set LogFormat (common) to:

%a %l %u %t \"%r\" %>s %b

These are the field values documented by cPanel. %a logs the client address supplied through mod_remoteip; preserve the quoted request and header fields.

Select Save, then Rebuild Configuration and Restart Apache. Check the operation’s result before continuing.

Verify the visitor address

Make a new request through the configured proxy and check the corresponding Apache access log entry. Confirm that it records the expected visitor IP rather than the proxy address.

If it still records the proxy, check the active header, trusted proxy addresses and conflicting configuration. Verify the setup again after configuration changes or updates.