{"id":1803,"date":"2016-01-01T00:17:08","date_gmt":"2016-01-01T00:17:08","guid":{"rendered":"http:\/\/emtunc.org\/blog\/?p=1803"},"modified":"2017-02-24T15:13:12","modified_gmt":"2017-02-24T15:13:12","slug":"installing-mod_cloudflare-ubuntu-14-04-apache-server","status":"publish","type":"post","link":"https:\/\/emtunc.org\/blog\/01\/2016\/installing-mod_cloudflare-ubuntu-14-04-apache-server\/","title":{"rendered":"Installing mod_cloudflare on Ubuntu 14.04 for Apache Server"},"content":{"rendered":"<p>In this article I will briefly go through instructions on installing mod_cloudflare on an Ubuntu 14.04 server running Apache 2.4.<\/p>\n<p>The reason we need the mod_cloudflare module is because Cloudflare acts as a reverse proxy meaning that visitor IP addresses in your access\u00a0logs (\/var\/log\/apache2\/access.log) will appear to come from any one of Cloudflare&#8217;s\u00a0IP addresses; all of which they make available <a href=\"https:\/\/www.cloudflare.com\/ips\/\" target=\"_blank\">here<\/a>.<\/p>\n<p><!--more--><\/p>\n<p>You can quickly confirm this fact by running the following:<\/p>\n<pre class=\"lang:default decode:true\">sudo tail -f -n 1 \/var\/log\/apache2\/access.log<\/pre>\n<p>Now access your site and check the request come in. Compare the IP to the <a href=\"https:\/\/www.cloudflare.com\/ips\/\" target=\"_blank\">Cloudflare IP range<\/a> &#8211; you should see a match.<\/p>\n<h3>Installing mod_cloudflare &#8211; Option A<\/h3>\n<p>This is the lesser known but preferred solution as it doesn&#8217;t require you to install between fifty and a hundred new packages to your system &#8211; you&#8217;ll know what I&#8217;m talking about when I get to Option B.<\/p>\n<p>First we need to add the official Cloudflare repository as a source in our Ubuntu set-up. For this we need to run the following:<\/p>\n<p>Here we are creating a new file called cloudflare-main.list in the \/etc\/apt\/sources.list.d directory and adding a single line to the file:<br \/>\ndeb http:\/\/pkg.cloudflare.com\/ <strong>trusty<\/strong> main<br \/>\nHere trusty is the Ubuntu release codename. Trusty = 14.04, Precise = 12.04, Utopic = 14.10 and Vivid = 15.04<\/p>\n<pre class=\"lang:default decode:true\">echo 'deb http:\/\/pkg.cloudflare.com\/ trusty main' | sudo tee \/etc\/apt\/sources.list.d\/cloudflare-main.list\r\n\r\n<\/pre>\n<p>Now we want to add the public GPG key for the Cloudflare repository so that apt can authenticate the packages (tip: see all keys by running apt-key list)<\/p>\n<pre class=\"lang:default decode:true\">curl -C - https:\/\/pkg.cloudflare.com\/pubkey.gpg | sudo apt-key add -\r\n<\/pre>\n<p>As we&#8217;ve just added the Cloudflare repo, we should update the apt cache by running:<\/p>\n<pre class=\"lang:default decode:true\">sudo apt-get update\r\n<\/pre>\n<p>Now we can see all packages we can install from the Cloudflare repo:<\/p>\n<pre class=\"lang:default decode:true\">grep ^Package: \/var\/lib\/apt\/lists\/pkg.cloudflare.com_dists_trusty_main_binary-amd64_Packages<\/pre>\n<p>You&#8217;ll see a number of packages. The one we&#8217;re interested in is called libapache2-mod-cloudflare<\/p>\n<p><a href=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2015\/12\/2015-12-31-23_26_20-Add-New-Post-\u2039-emtuncs-Blog-\u2014-WordPress.png\" rel=\"attachment wp-att-1805\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1805\" src=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2015\/12\/2015-12-31-23_26_20-Add-New-Post-\u2039-emtuncs-Blog-\u2014-WordPress.png\" alt=\"2015-12-31 23_26_20-Add New Post \u2039 emtunc's Blog \u2014 WordPress\" width=\"942\" height=\"61\" srcset=\"https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2015\/12\/2015-12-31-23_26_20-Add-New-Post-\u2039-emtuncs-Blog-\u2014-WordPress.png 942w, https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2015\/12\/2015-12-31-23_26_20-Add-New-Post-\u2039-emtuncs-Blog-\u2014-WordPress-300x19.png 300w, https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2015\/12\/2015-12-31-23_26_20-Add-New-Post-\u2039-emtuncs-Blog-\u2014-WordPress-768x50.png 768w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/a><\/p>\n<p>Let&#8217;s install mod_cloudflare by running the following:<\/p>\n<pre class=\"lang:default decode:true\">sudo apt-get install libapache2-mod-cloudflare<\/pre>\n<p>You&#8217;ll see some output and after a few seconds, the module will automatically load<\/p>\n<p><a href=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2015\/12\/2015-12-31-23_29_21-mtunc@emtlab-ubuntu01_-.png\" rel=\"attachment wp-att-1806\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1806\" src=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2015\/12\/2015-12-31-23_29_21-mtunc@emtlab-ubuntu01_-.png\" alt=\"2015-12-31 23_29_21-mtunc@emtlab-ubuntu01_ ~\" width=\"741\" height=\"320\" srcset=\"https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2015\/12\/2015-12-31-23_29_21-mtunc@emtlab-ubuntu01_-.png 741w, https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2015\/12\/2015-12-31-23_29_21-mtunc@emtlab-ubuntu01_--300x130.png 300w\" sizes=\"auto, (max-width: 741px) 100vw, 741px\" \/><\/a><\/p>\n<p>Now all that&#8217;s left is to restart Apache by running:<\/p>\n<pre class=\"lang:default decode:true\">sudo service apache2 restart<\/pre>\n<p>That&#8217;s it! You can confirm the presence of the module by checking the access.log just like we did at the beginning of this blog. You can also run the command below which will spit out all active Apache modules:<\/p>\n<pre class=\"lang:default decode:true\">sudo apache2ctl -M<\/pre>\n<h3>Installing mod_cloudflare &#8211; Option B<\/h3>\n<p>The more &#8216;advertised&#8217; method of installing mod_cloudflare on Ubuntu 14.04 is the one on the official Cloudflare pages. It basically involves cloning the mod_cloudflare git repo and compiling the source code in to an Apache module. This process requires many dependencies which is why I don&#8217;t like it.<\/p>\n<p>First we need to install the dependencies:<\/p>\n<pre class=\"lang:default decode:true\">sudo apt-get install apache2-dev libtool git<\/pre>\n<p>Now clone the git repo to a location of your choice. I put mine in \/var\/www\/:<\/p>\n<pre class=\"lang:default decode:true\">cd \/var\/www\r\ngit clone https:\/\/github.com\/cloudflare\/mod_cloudflare.git\r\ncd mod_cloudflare<\/pre>\n<p>Now we build the Apache usable module from the\u00a0source file <strong>mod_cloudflare.c<\/strong>:<\/p>\n<pre class=\"lang:default decode:true\">apxs -a -i -c mod_cloudflare.c<\/pre>\n<p>Now all you need to do is restart Apache and confirm that the module is active by testing it!<\/p>\n<pre class=\"lang:default decode:true\">sudo service apache2 restart\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this article I will briefly go through instructions on installing mod_cloudflare on an Ubuntu 14.04 server running Apache 2.4. The reason we need the mod_cloudflare module is because Cloudflare acts as a reverse proxy meaning that visitor IP addresses in your access\u00a0logs (\/var\/log\/apache2\/access.log) will appear to come from any one of Cloudflare&#8217;s\u00a0IP addresses; all [&hellip;]<\/p>\n","protected":false},"author":32,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"categories":[1],"tags":[218,216,217,214],"class_list":["post-1803","post","type-post","status-publish","format-standard","hentry","category-tech","tag-apache","tag-cloudflare","tag-mod_cloudflare","tag-ubuntu"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1trTO-t5","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/1803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/comments?post=1803"}],"version-history":[{"count":9,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/1803\/revisions"}],"predecessor-version":[{"id":2478,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/1803\/revisions\/2478"}],"wp:attachment":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/media?parent=1803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/categories?post=1803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/tags?post=1803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}