We recently switched to CloudFlare for our own website but even after a lot of research could not find proper documentation moreover mod_cloudflare has been discontinued and all documents are too old, so here is how we fixed it.
- First login to WHM
- Customise your Apache config and under Apache Modules select mod_remoteip (yes we will use mod_remoteip instead of mod_cloudflare)
- Once Apache is recompiled now you need to edit a file with name “370_mod_remoteip.conf” it may be 360 or 350 or something else but last part will be “mod_remoteip.conf” and file is available in /etc/apache2/conf.modules.d.
- Just add following to above file:
RemoteIPHeader X-Real-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
5. Now go to WHM and under “Apache Configuration” click on “Include Editor” then under “Pre Main Include” edit the file and add:
<IfModule remoteip_module>
RemoteIPHeader X-Forwarded-For
</IfModule>
<IfModule log_config_module>
LogFormat “%{Referer}i -> %U” referer
LogFormat “%{User-agent}i” agent
LogFormat “%a %l %u %t \”%r\” %>s %b” common
LogFormat “%a %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” combined
CustomLog logs/access_log combined
</IfModule>
Now just save and restart Apache, it should now start showing your real IP in apache logs etc…