Skip to main content
Drupal + Cloudflare

If you're running a small Drupal site on limited space like I am, you'll probably not have more than 30 GB for hard disk space and maybe 2 vCPU and 2 GB RAM on your server. This could be affect your Drupal site speed if there are a lot of images or even with time as the content grows, you'll have server load issues. I've optimized my site so much that the performance is 98-100 on most pages and still able to sustain a viewership of 250 - 500 views per day without the server freaking out. Drupal cache with Cloudflare CDN is the solution!

Let's go into how I've done this.

Since I've started uploading more pictures and because of my placeholder/dummy image service I've realized I would soon run out of space! So I've decided to shift all my assets to AWS S3. You can read more about how to do that here. This allows me take my mind of storage because S3 on a standard config will take a loooong time before it starts costing me serious money. Currently it has cost me only 2 INR or so which is like 20 cents. So now the images are being loaded from S3, and it's helping my tiny server breathe.

Now, if you have a lot views and the LIST/SELECT requests on your S3 bucket are going up, you will see an uptick in the AWS S3 billing. You can reduce this and speed up your site using Cloudflare CDN cache. The free version of Cloudflare is more than enough for this. The solution is to proxy your images through Cloudflare network and allow Cloudflare to cache everything.

Steps to do this:

  1. Create a Cloudflare account and add your site to Cloudflare.
  2. Enable all recommendations by Cloudflare, usually this wouldn't cause any issues for 90% of the sites out there. But the rest might have issues when CSS and JS files are minified and/or other optimizations are done.
  3. When you're adding your site and changing nameservers to use Cloudflare network, make sure you check the box that proxies requests through Cloudflare.
    Cloudflare DNS
  4. Now you need to add a CNAME record for your s3 bucket. For example, I've used as my bucket name and have added a CNAME record that points to my actual bucket url. You can read more about AWS s3 bucket URL types here.
  5. In your AWS s3 settings for your Drupal module, you have check the box that says enable CNAME and put in your CNAME record.
  6. Clear Drupal and Cloudflare cache, your images will load from S3 using the new domain CNAME and it will be proxied through Cloudflare. This means Cloudflare is now able to cache your images from S3 bucket as well. This means fewer requests to your S3 bucket, lower costs and a faster site!

You're welcome! :)



Therefore logo
80 Atlantic Ave, Toronto, ON Canada
Call us: +1 4166405376

Let us know how we can help!