Using Backblaze B2 with the Cloudflare CDN

Configuring Cloudflare and B2

The partnership between Backblaze and Cloudflare enables storing content on Backblaze's B2 storage service and automatically feeding it as needed into Cloudflare's CDN (Content Delivery Network). This permits content to live in Backblaze B2, yet be delivered with the low latency and high speed of one of the world's premier CDNs.  The content consumer sees no difference as they use the same URLs and access the site exactly as before - only with the speed and reliability of Cloudflare.
 
As a webmaster, however, you can make full use of Cloudflare's capabilities such as Edge cache expire TTL. Another explanation for how to configure edge cache can be found here.

Feed the CDN from a public B2 bucket

Login to your Backblaze B2 account, and locate (or create) the bucket which will contain the content for the CDN.  Please note: the instructions below are how to configure a public B2 bucket for the Cloudflare CDN.  If you would like to allow Cloudflare to fetch content from a Backblaze B2 private bucket, follow the instructions below. Then, read the KB article for how to use Cloudflare Workers to fetch content from a B2 private bucket.
 
 

Discover the B2 public URL for this bucket

The URL to display the file should be either https://f000.backblazeb2.com, https://f001.backblazeb2.com or something similar. Clicking on the link should take you to the image. Please note: If clicking on this link generates and error, the bucket may be private rather than public.  Toggle the bucket's public/private status from the B2 web UI.

 

Configuring Cloudflare to use B2

Visit https://www.cloudflare.com/a/sign-up and log into your account (Or Signup for an account).

 

Configure Cloudflare to handle requests to your domain with content from the Backblaze B2 bucket

Add your domain to the bottom of the screen and tap scan. Cloudflare will read your domain's configuration from DNS. When the scan is complete, push Continue.

 

Add DNS (Domain Name System) records

Each section of a website that is being fed from a Backblaze B2 bucket requires a specific entry.  For example, a site might have separate areas for photos and videos.  Remapping photos looks like this:

  1. Select CNAME (Canonical Name) from the record type pulldown.
  2. Type your hostname. To map the bucket to photos.mydomain.com, the Name field would be photos.
  3. Specify the B2 public URL, from the first step. For example, f000.backblazeb2.com.
  4. Push "Add Record".
 

Complete the DNS record

Tap the grey cloud under Status. This should turn it into an orange cloud.

Push Continue at the bottom of the page.

 

Configure Page Rules to allow only your bucket to be fetched from your domain

The DNS configuration maps your domain to any content hosted on Backblaze B2. Therefore, someone can use your domain to fetch content from another customer's bucket. To ensure this doesn't happen, Cloudflare allows you to use Page Rules to scope requests to your bucket.

To configure, click "Page Rules" from the top navigation and add a rule for each bucket allowing Cloudflare to cache that content. The last rule should redirect to a "file not found" page, such as the one on the Backblaze website. 

In the example below, the bucket name is "nilayp". If a request is made to https://photos.sarahandnilay.com/file/nilayp/* , Cloudflare will return the content requests. A request to any other bucket will be redirected.

 Page_Rules___sarahandnilay_com___Nilayp_gmail_com_s_Account___Cloudflare_-_Web_Performance___Security.jpg

 

Billing

Select the desired Cloudflare billing plan that's appropriate for you. The free website option works with B2 and can be used. For more information about Cloudflare's capabilities, please visit Cloudflare's service plan page. Push continue to go on.

 

Change the nameservers for the domain

In order for Cloudflare to map your domain on a B2 bucket, Cloudflare must be the domain nameserver for your domain. This is typically done from your domain registrar's website. Please note: Be careful when changing the settings for your domain. If you don't do this correctly - your domain could be temporarily removed from the internet until the settings are corrected.

Once this change is made - it can take at most 24 hours for the changes to propagate across the internet.

 

Ensure the SSL settings are correct.

Ensure your SSL settings are set to Full. This is the default setting.  Please note: Backblaze B2 only supports secure (HTTPS) connections.

If you have any questions regarding how to set your SSL settings in Cloudflare please review: https://support.cloudflare.com/hc/en-us/articles/200170416-What-do-the-SSL-options-mean-
This article will show you how to make sure that Cloudflare uses SSL to the origin using FULL mode.

 

 

Finished

Once the DNS changes are propagated, the domain will serve data directly from the Backblaze B2 cloud storage bucket. The Cloudflare configuration screen will show the Status as being active.

Browsing to your domain, followed by /file/<bucketname>/filename will display your file.

For example, from the screenshots above, https://photos.sarahandnilay.com/file/nilayp/img.jpg is mapped to https://f000.backblazeb2.com/file/nilayp/img.jpg

Note that this only works using https:// or SSL. Unencrypted HTTP (http://) is not supported by Backblaze B2.

 
Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk