CloudFlare: Restore original visitor IP to Apache Web Servers

By | July 8, 2012

Since CloudFlare acts as a reverse proxy for websites, CloudFlare’s IPs are going to show in your server logs. This can be easily identified from awstats or webalizer.
cloudflare
There is an easy fix to restore original visitor IP for any web server.
1) Copy the source file mod_cloudflare.c to your web server.
wget https://raw.github.com/cloudflare/CloudFlare-Tools/master/mod_cloudflare.c
2) Make sure that the command apxs or apxs2 is installed somewhere.
If you are running Ubuntu or Debian, this can be installed with:

apt-get install apache2-prefork-dev

If you are running Fedora or CentOS, this can be installed with:

yum install httpd-devel

3) Execute this command as root:

apxs2 -iac mod_cloudflare.c

4) Restart apache.
5) Lastly, make sure that mod_cloudflare is working by tailing your access.log file. ou should see that the remote_ip field here is no longer that of the CloudFlare CDN IP ranges. You can execute this command to verify mod_cloudflare is loaded into Apache:

apachectl -t -D DUMP_MODULES | grep cloud

Related article

Loading