Installing mod_cloudflare On CentOS With Apache and DirectAdmin

Installing mod_cloudflare On CentOS With Apache and DirectAdmin


  • Share on Pinterest

CloudFlare is pretty awesome. But anyone who uses the service and has needed to analyze web server logs realizes that due to CloudFlare working as a proxy, all IP addresses logged are those belonging to the CloudFlare network. This can cause some headaches if you’re attempting to troubleshoot issues like abuse or if your web application relies on real visitor IP addresses. Because of this, CloudFlare has provided their own module which alleviates this. Documentation on the module here, and use cases here.

Installation of this module is rather straight forward, but if you’re using DirectAdmin then there’s a few slight adjustments that need to be made due to their use of the httpd-includes.conf file. Don’t worry, it’s still super simple.

For this guide, I used CentOS 6.8 with Apache 2.4.


Installation

1) First things first, I’d recommend making a backup of your Apache configuration directory.

cp -a /etc/httpd/conf/ /etc/httpd/conf.`date +%Y%m%d`/

2) Download the module.

wget https://www.cloudflare.com/static/misc/mod_cloudflare/mod_cloudflare.c

3) Install the module.

apxs -a -i -c mod_cloudflare.c

4) Add mod_cloudflare to DirectAdmin’s httpd-includes file.

echo "LoadModule cloudflare_module /usr/lib/apache/mod_cloudflare.so" >> /etc/httpd/conf/extra/httpd-includes.conf

5) Open /etc/httpd/conf/httpd.conf with a text editor and comment out the LoadModule line like so:

#LoadModule cloudflare_module

6) Restart Apache and use httpd -M to verify the mod_cloudflare module is showing as loaded.