Currently using’s CDN Solution from:https://www.eallion.com/cdn-cname-cloudflare/ Take a look at the CDN structure diagram. Our goal is to solve the global CDN problem at a low cost.Documentation Index
Fetch the complete documentation index at: https://base.bangwu.me/llms.txt
Use this file to discover all available pages before exploring further.
Previous articleBackup
Introduction
domestic and overseas traffic splitting,not only reduces costs,but also improves website performance,optimizes TTFB。 I don’t remember when I started having such thoughts, so I went to search for it. It turns out that the tutorials online are quite old. Where most of the talk’s is access to CNAME is through Cloudflare for SaaS, but it doesn’t support regular domain names, and can’t access R2 or Workers. In terms of function’s priority, I need the partition resolution function most, which results in the inability to transfer the domain name’s NS to Cloudflare. Cloudflare’s DNS is indeed excellent, but Cloudflare doesn’t support geo-based resolution, it has CNAME flattening, but it will resolve all mainland China’s IPs to China Unicom. On the contrary, domestic DNS service providers do a good job in partition resolution, maybe because domestic domain names need this function more. Can’t fully commit, but want to use Cloudflare, so have to use some tricks. In March 2022, Cloudflare announced changes to Cloudflare for SaaS’s charging strategy. Each account can have 100 free domain names, and charges $0.1/month per extra domain. We use Cloudflare for SaaS to connect domains via CNAME and enjoy Cloudflare’s powerful edge calculation capabilities. Yes for small websites, such as this blogs, the above services are free’s, free quota:- DNSPod: Use’s professional version, but freeversions also has partition resolution
- Tencent Cloud COS: 50G/month; 2 million requests
- Tencent Cloud CDN: 10G/month
- Cloudflare CDN: No upper limit for normal use
- Cloudflare R2: 10G/month; 1 million/10 million requests
- Backblaze B2: 10G/month; has [Traffic Alliance] with Cloudflare(https://www.backblaze.com/cloud-storage/integrations)
回退源 (Fallback Origin), assuming this domain name is example.com.
Create R2 and bind a custom domain name
- Log in to the control panel: https://dash.cloudflare.com/, Cloudflare supportsChinese;
- Create R2 bucket’s Method is skipped here, for example, create:
r2-blog-test; - in
R2设置公开Visit自Definition域连接域Add a custom domain name to the ‘s R2 you just created:
Then the domain name’s DNS will automatically appear with a resolution:
Subscribe to Cloudflare for SaaS
- Select the domain name
example.cominZones; - Select
自Definition主机名in the domain name’sSSL/TLS; - Select Enable Subscription. Subscriptions can be made using Paypal.
Add custom domain name
After the subscription is successful, first add回退源:images.example.com. This return-to-origin domain name is bound in R2’s self-defined domain name.
Then click 添加自Definition主机名 and fill in the CDN domain name, such as images.eallion.com. The recommended validation method is TXT Validation.
After adding, you need to validate the domain name. Go to your own domain name resolution console, such as DNSPod, and add 2 TXT records.
Wait for both 证书State and 主机名State to become 有效.
Parse CNAME
After回退源State 证书State and 主机名State become 有效, go to your own domain name resolution console to add CNAME resolution.
Point the production environment’s images.eallion.com CNAME to images.example.com.
Normally’s tutorial ends here.
But this way isVisit doesn’t work with R2’s resources.
The most important step, use Worker Proxy R2.
Create new Worker Proxy R2
There is official documentation on how to pass Worker Visit R2: Use R2 from Workers:https://developers.cloudflare.com/r2/api/workers/workers-api-usage/ Just follow the documentation tutorial step by step. If you are lazy, you don’t want to authenticate. Then just use my streamlined code. TheDELETE and PUT ‘s codes are directly removed, leaving only GET.
Workers can be created manually in the background without Wrangle CLI scripts.
Switch to the Worker 和 Pages column on the left, 创建应用程序, just give it a name, choose a template Deployment, and change the code later.
Click 快速edit to copy the following code to worker.js, save and Deployment:
Variable R2 存储桶绑定 add binding:
Variablename:MY_BUCKETR2 存储桶: Select yes should’s bucket
Workers routing
Go back to Zones, select the domain name, and add Workers routing:路由: Be sure to fill in the production environment’s domain name, do not fill in Cloudflare’s source domain name, such as:images.eallion.com/*;Worker: Select the previous step to create’s Worker;环境:Production.
At this point, you should be able to visit Cloudflare R2’s content using CNAME’s method.
Worker Proxy Backblaze B2
In fact, R2 is enough, but B2 may be needed for various reasons. Actually it’s pretty much the same. Backblaze also has official documentation introducing how to visit B2 through Cloudflare Worker. Docs: Integrate Cloudflare Workers with Backblaze B2 Let’s briefly introduce how to do it: (It is also recommended to read Official Docs.)1. Create a new Cloudflare Worker, worker.js
2. Set Worker Environment Variables
ALLOW_LIST_BUCKET:trueB2_APPLICATION_KEY:K004WJZP11111111111111111111QB2_APPLICATION_KEY_ID:0042e9999999920000000001B2_ENDPOINT:s3.us-west-004.backblazeb2.comBUCKET_NAME:eallion-static
B2_ENDPOINT needs to be viewed in its own B2 bucket.
3. Manually add CNAME to resolve to B2
类型: SelectCNAMEname: used for回退源, such as:b2.example.com, fill inb2内容: Fill in your own B2 bucket allocation’sS3 URL, there’s a tutorial here written byisFriendly URL, it’s not necessary, there is one more step to reverse generation.
4. Configuration fallback source
Zones’s domain name is Backblaze B2. Set’s CNAME name is whatever it is, then fill in whatever the fallback source is, such as: b2.example.com.
Just refer to the previous article.
5. Configuration self-defined host name
Refer to the previous article.6. Configuration Worker routing
路由: Be sure to fill in the production environment’s domain name, do not fill in Cloudflare’s source domain name;Worker: Select the previous step to create’s Worker;环境:Production.
b2.example.com/*also needs to be added to the Worker routeimages.eallion.com/*
