How to install mod_cloudflare on Apache for Ubuntu

http_logs

When you use CloudFlare CDN it acts as a proxy to your content and distributes it all around the world. Therefore in your raw HTTP access logs you’ll see the CloudFlare hostnames as opposed to the original IP address.

Although you have analytics installed sometimes it’s important (and legally required sometimes) to have full logs available. Following the steps below will change your access logs from:

cf-173-245-53-63.cloudflare.com – - [10/Sep/2011:20:23:44 +0100] “GET /wp-content/themes/premiumpixels/images/bg-side-bevel.gif HTTP/1.0″ 200 35
cf-173-245-53-63.cloudflare.com – - [10/Sep/2011:20:23:44 +0100] “GET /wp-content/themes/premiumpixels/images/bg-footer.gif HTTP/1.0″ 200 1698
cf-173-245-49-107.cloudflare.com – - [10/Sep/2011:20:23:44 +0100] “GET /wp-content/themes/premiumpixels/images/bg-foot-inner.jpg HTTP/1.0″ 200 68030
cf-173-245-53-64.cloudflare.com – - [10/Sep/2011:20:23:45 +0100] “GET /favicon.ico HTTP/1.0″ 200 -
cf-173-245-55-86.cloudflare.com – - [10/Sep/2011:20:30:34 +0100] “GET /favicon.ico HTTP/1.0″ 200 -
cf-173-245-56-238.cloudflare.com – - [10/Sep/2011:20:31:09 +0100] “GET /tag/iseb HTTP/1.0″ 200 6162

To something more ‘traditional’ like this:

2.27.164.2 – - [10/Sep/2011:20:38:23 +0100] “GET / HTTP/1.0″ 200 7556
2.27.164.2 – - [10/Sep/2011:20:38:24 +0100] “GET /wp-includes/js/l10n.js?ver=20101110 HTTP/1.0″ 200 221
2.27.164.2 – - [10/Sep/2011:20:38:24 +0100] “GET /wp-content/uploads/2011/08/Wordpress-FTP-details-dialogue-300×126.png HTTP/1.0″ 200 22726
crawl-66-249-72-115.googlebot.com – - [10/Sep/2011:20:44:18 +0100] “GET /tag/mac HTTP/1.0″ 200 6089

There is an excellent how to available over on the CloudFlare wiki, put here for ease of use.

logon via SSH to your box

Type in the following commands:

cd /root
wget http://github.com/cloudflare/CloudFlare-Tools/raw/master/mod_cloudflare.c
apt-get install apache2-prefork-dev
apxs2 -iac mod_cloudflare.c
sudo /etc/init.d/apache2 restart

(Update 30 Dec 2013 – There is now an easier way, thanks Dan.)

Type in the following commands:

cd /root
wget https://www.cloudflare.com/static/misc/mod_cloudflare/ubuntu/mod_cloudflare-precise-amd64.latest.deb
dpkg -i mod_cloudflare-precise-amd64.latest.deb
apt-get install apache2-prefork-dev
apxs2 -iac mod_cloudflare.c
sudo /etc/init.d/apache2 restart

Test it:

tail -f /[path to apache logs/access.log

Open up a website you host and you should now see the original IP address in your logs.

5 Comments on "How to install mod_cloudflare on Apache for Ubuntu"

Trackbacks for this post

  1. How to Install Mod CloudFlare – Apache « aaronprice04

Got something to say? Go for it!