banner
老孙

老孙博客

资深网民孙先生
mastodon
email

Complete process of integrating Backblaze with Cloudflare custom domain

Backblaze offers 10GB of free storage space, and after connecting to Cloudflare, there is no download traffic.

  1. Create a new bucket in Backblaze.

Then upload any file inside and check the friendly URL address.

  1. Parse the CNAME domain in Cloudflare.

The goal is the friendly URL address provided by the Backblaze bucket, for example, mine: f005.backblazeb2.com.

Note: If your Cloudflare domain is routed through a partner hosting area, such as connecting to third-party platforms like DreamHost, and you are still using the CNAME connection method, meaning you cannot directly add parsing in the Cloudflare backend, it will not work properly, such as SSL and rules.

There should be a way to solve this, but I couldn't find it on the official website. If anyone knows, please let me know.

  1. Set the SSL for the Cloudflare domain.

The official recommendation is to set it to: Full (Strict), but I am used to: Full.

You can also set it separately in the rules.

  1. Set the rules for the Cloudflare domain.

Rule 1: Rewrite the URL path, which means hiding the name of the Backblaze bucket.

Rule – Transform Rules – Add Rewrite URL Rule:

Since a subdomain is used, select: Custom Filter Expression, where the hostname, URL equals or contains the domain you parsed.

Then rewrite rule: choose Dynamic

concat("/file/jingxialai", http.request.uri.path)
#/file/ is the fixed folder name for Backblaze
#jingxialai should be replaced with your own bucket name
#Then save

Rule 2: Remove HTTP headers from the response.

Rule – Transform Rules – Add Modify Response Header Rule.

Add a delete rule, header names:

x-bz-content-sha1
x-bz-file-id
x-bz-file-name
x-bz-info-src_last_modified_millis
x-bz-upload-timestamp
Currently, x-bz-info-src_last_modified_millis seems to be missing, but it is included in the official tutorial, so I added it.

Everything else can remain the same as the previous rewrite URL settings, then save.

Rule 3: Optimize cache efficiency through ETag and Cache-Control HTTP headers.

Rule – Transform Rules – Response Header Rules.

Just add a new entry in the previous HTTP response header modification rules:

Set Dynamic – Header Name: ETag

Add value:

concat(http.response.headers["x-bz-content-sha1"][0], http.response.headers["x-bz-info-src_last_modified_millis"][0], http.response.headers["x-bz-file-id"][0])

Now let's check the response header information for the images we uploaded to Backblaze:

The x-bz prefixed names are gone, and there is an ETag value.

  1. Set the cache rules for the Backblaze bucket and Cloudflare domain.

Set as needed.

Cloudflare Rules – Add a Page Rule.

URL: Parsed domain/*

Cache Level: Cache Everything

Edge Cache TTL: I set it to 1 month.

Set the cache time for the Backblaze bucket.

Bucket Settings – Bucket Info: 720000, this time can be modified by yourself, in seconds.

{"cache-control":"max-age=720000"}

Now let's access the files uploaded to Backblaze and check the response header information:

cache-control: max-age=720000
cf-cache-status: HIT (indicating successful caching)

That's about it. As for whether to set up anti-leech protection, it depends on your needs.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.