> ## Content Index
> Fetch the complete content index at: https://horrell.ca/llms.txt
> Use this file to discover other available public pages before exploring further.

# Installing mod_cloudflare on a Joyent SmartMachine
- URL: https://horrell.ca/2012/02/12/installing-mod_cloudflare-on-a-joyent-smartmachine/
- Published: 2012-02-12T17:17:00.000Z
- Updated: 2019-05-03T17:55:28.000Z
- Author: Christopher Horrell
- Tags: Joyent, CloudFlare, #Import 2024-10-01 02:36

[CloudFlare](http://www.cloudflare.com/?ref=horrell.ca "CloudFlare") is a great service and I’ve been using for my horrell.ca site for some time. It speeds everything up, acts as a firewall protecting your site from bots and jerks, and also provides [IPv6 support](http://blog.cloudflare.com/introducing-cloudflares-automatic-ipv6-gatewa?ref=horrell.ca). One side affect of using CloudFlare is the Apache logs for your site will show IP addresses from the CloudFlare network for any site visitors rather than the true visitors IP address. You can fix that by installing the [mod\_cloudflare Apache module](https://github.com/cloudflare/CloudFlare-Tools?ref=horrell.ca).

Here’s how to install it on a new [Joyent SmartMachine](http://www.joyentcloud.com/products/pricing/smartos-linux/?ref=horrell.ca)

1. First, download the [mod\_cloudflare.c](https://github.com/cloudflare/CloudFlare-Tools/blob/master/mod%5Fcloudflare.c?ref=horrell.ca) source file from CloudFlare’s [Github repos](https://github.com/cloudflare/?ref=horrell.ca) (the -L flag makes sure `curl` follows any redirects):  
```  
<pre><code>curl -OL https://raw.github.com/cloudflare/CloudFlare-Tools/master/mod_cloudflare.c</code></pre>  
```
2. Install the gcc compiler:  
```  
pkgin install gcc47  
```
3. Now compile and install the module:  
```  
<pre><code>apxs -c -i mod_cloudflare.c</code></pre>  
<p>If you have a 64 bit machine, you&#8217;ll need to use something like this instead:</p>  
<pre><code>apxs -Wc,-m64 -Wl,-m64 -c -i mod_cloudflare.c</code></pre>  
```
4. Set the permissions:  
```  
<pre><code>chmod 755 /opt/local/lib/httpd/mod_cloudflare.so</code></pre>  
```
5. Add this to /opt/local/etc/httpd/includes/dso.conf (this will load the module when Apache starts):  
```  
<pre><code>LoadModule cloudflare_module lib/httpd/mod_cloudflare.so</code></pre>  
```
6. Now refresh Apache to load the module:  
```  
<pre><code>svcadm refresh apache</code></pre>  
```

And that’s it! If you check your Apache logs (`/var/log/httpd/access.log` or `/home/NAMEOFSITE/logs/access.log`) you should start seeing accurate IP addresses.

You can check if the installation went smoothly with:

```
svcs -vx apache

```

If Apache is in *maintenance*, chances are something went wrong with loading the module. The `/var/svc/log/network-apache:default.log` service log file will give an idea of what you need to fix.

Periodically, CloudFlare adds new IP addresses to their network, so you’ll need to reinstall the module. You don’t need to do anything special for that, just repeat the above steps using the updated mod\_cloudflare.c. source file. I follow the git repos for changes (which doesn’t happen that often).