Learn how to install mod_cloudflare and log your visitor’s original IP address at your origin server.
For example, if you install applications that depend on the incoming IP address of the original visitor, a Cloudflare IP address is logged by default. The original visitor IP address appears in an appended HTTP header called CF-Connecting-IP. With the mod_cloudflare tool, you can log the original visitor IP address at your origin server.
The diagram below illustrates the different ways that IP addresses are handled with and without Cloudflare.
There are two methods for installing mod_cloudflare: by downloading the Apache extension from Github or by adding code to your origin web server.
Downloading packets or scripts from Github
If you are using an Apache web server, you can download mod_cloudflare from Github.
Adding code to your origin web server
If you can't install mod_cloudflare, or if there is no Cloudflare plugin available for your content management system platform to restore original visitor IP, add this code to your origin web server in or before the <body> tag on any page that needs the original visitor IPs:
<?php if (isset($_SERVER['HTTP_CF_CONNECTING_IP']))
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];?>
This command will only make the IP address available to scripts that need it. It doesn’t store the IP in your actual server logs.
To remove mod_cloudflare, you should comment out the Apache config line that loads mod_cloudflare.
This varies based on your Linux distribution, but for most people, if you look
in /etc/apache2, you should be able to search to find the line:
Comment or remove this line, then restart apache, and mod_cloudflare should be gone.
If you are running Ubuntu or Debian, you should see.
delete this file to remove mod_cloudflare, then restart Apache.
Mod_cloudflare is installed by modifying the nginx configuration file
nginx.conf with the
To remove mod_cloudflare you should comment or remove this line, then restart nginx, and mod_cloudflare should be gone.