Configuring Cloudflare and B2
Feed the CDN from a public B2 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:
- Select CNAME (Canonical Name) from the record type pulldown.
- Type your hostname. To map the bucket to photos.mydomain.com, the Name field would be photos.
- Specify the B2 public URL, from the first step. For example, f000.backblazeb2.com.
- 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.
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.
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.