Page Rules
For ROSE Online we store our game update archives in Backblaze B2 and serve them directly to our players. When we initially set things up we simply setup a CNAME for our subdomain to our public bucket URL, e.g.
CNAME updates rose-updates.s3.us-west-002.backblazeb2.com
Our intention was that https://updates.roseonlinegame.com
would be an alias
for the backblaze bucket and files could be retrived directly. Unfortunately
this doesn't work as expected due to limitations on the Backblaze side so we had
to setup a rewrite rule in Cloudflare using Page Rules to actually make this work.
updates.roseonlinegame.com/*
Forwarding URL (Status Code: 301 - Permanent Redirect, Url: https://rose-updates.s3.us-west-002.backblazeb2.com/$1)
This is actually the guidance recommended by Backblaze in their official documentation: https://www.backblaze.com/docs/cloud-storage-deliver-public-backblaze-b2-content-through-cloudflare-cdn.
In practice this achieved our goal but there were three main downsides:
- Users were exposed to the b2 URL through the redirect
- Backblaze is blocked in some countries so some of our players could not receive updates
- Backblaze is not a CDN so download speeds were slow for some of our players
Transform Rules
We recently have been working on our update process and decided to revist this issue. Since our original implementation Cloudflare has released "Transform Rules" which provide a superior solution.
First, we re-established the CNAME DNS record, (using updates2
to avoid
service interruptions) but this time we use the base Backblaze B2 domain for our bucket e.g.
CNAME updates2 f002.backblazeb2.com
and then using a transform rule we can rewrite this URI so that any path components after the domain name only reach our bucket, e.g.
If...
When incoming requests match…
Custom filter expression
The rule will only apply to traffic matching the custom expression
(http.host eq "updates2.roseonlinegame.com")
Then…
Set Rewrite parameters
Path
Rewrite to...
Specify both the input and output pattern within the expression. Cannot be an empty value.
Dynamic concat("/file/rose-updates", http.request.uri.path)
Query
Preserve
The key line being concat("/file/rose-updates", http.request.uri.path)
.
With this rule Cloudflare will internally rewrite our URI so that
https://updates2.roseonlinegame.com/manifest.json
will fetch the files from
f002.backblazeb2.com/file/rose-updates/mainfest.json
and serve the files for
us. Now we get the benefit of using Cloudflare as a CDN, users who can't access
backblaze will not have anymore issues and we don't have to expose our ugly
backblaze url!