In your bunny.net account, go to the Delivery -> CDN tab and create a new pull zone.
Pick a name, set https://ziglang.org
as the origin, and choose "High Volume Tier", as we're going to be serving relatively large files.
Next, we need to set up a middleware script to route requests to the correct location.
Switch away from the CDN page to the Edge Platform -> Scripting tab in the sidebar, and add a new script. Select "Deploy With bunny.net", as the script is very simple and doesn't need a full Git repo.
Enter a name, such as "Zig mirror middleware", and select the "Middleware" script type, then click "Add Script".
Replace the contents of the code editor with the middleware.ts
in this Gist, replacing the value of CDN_BASE
with the base URL for your mirror.
Click "Connect Pull Zone" and select the pull zone you created in step 1, then click "Publish", followed by "Publish Script".
Finally, we need to enable perma-caching, so the CDN will store the zig archives for an extended period of time.
Navigate to the Delivery -> Storage tab, and add a new storage zone. Call it something like "zig-permacache", and select the Standard storage tier. Choose which regions you want to replicate to (the defaults are fine if you're not sure), and click "Add Storage Zone".
Once the storage zone is created, switch back to the CDN tab and select the pull zone you created in step 1. Do not use the "Connect Pull Zone" button in the storage zone settings.
In your CDN settings, select Caching -> Perma-Cache, then select the storage zone you created and click "Save Configuration".
You can test your mirror using curl, eg:
$ curl -I https://squirl-zig.b-cdn.net/zig-x86_64-linux-0.14.1.tar.xz
HTTP/2 200
date: Tue, 01 Jul 2025 03:18:51 GMT
content-type: application/octet-stream
content-length: 49086504
server: BunnyCDN-FR1-1187
cdn-pullzone: 4149629
cdn-uid: 06d8c2f4-3fdd-49b1-9680-d635eaa0ec3f
cdn-requestcountrycode: GB
cache-control: public, max-age=31919000
etag: "68308035-2ed0028"
last-modified: Fri, 23 May 2025 14:03:33 GMT
cdn-bess-version: 1.30.2
cdn-edgestorageid: 1187
cdn-proxyver: 1.31
cdn-requestpullsuccess: True
cdn-requestpullcode: 200
cdn-requesttime: 0
cdn-status: 200
cdn-cachedat: 07/01/2025 02:57:51
perma-cache: MISS
cdn-requestid: 8d840a94b714387a1a5bfb16f657a7e4
cdn-cache: HIT
accept-ranges: bytes
If you want, you can add a custom domain in your CDN settings, under General -> Hostnames.