For an R2 bucket that serves public thumbnails, why is the r2.dev URL wrong for production, and what does a custom domain change?
answer
- two independent ways to go public
- a variable rate limit and 429s
- a zone in the same account
- turn the development URL back off
basics
~20 sThe r2.dev URL is a rate-limited testing endpoint that returns 429 under load and cannot use caching, WAF or Access. A custom domain on a zone in the same account gives a production hostname that Cloudflare's cache and security rules can front.
solid answer
~50 sR2 buckets are private until you enable public access, which comes in two independent forms. The **public development URL** on `r2.dev` exists for testing: it applies a variable rate limit, so a few hundred requests per second bring `429 Too Many Requests` and throttled bandwidth, and it cannot use caching, WAF rules, Access or Bot Management. A **custom domain**, such as `thumbs.example.com`, must be a zone in the same Cloudflare account (full or partial setup); connecting it with `wrangler r2 bucket domain add` or the dashboard creates the DNS record, and from then on Cloudflare's cache and security products can front the bucket. Neither path charges egress. Two traps: enabling a custom domain does not disable `r2.dev`, so turn it off with `wrangler r2 bucket dev-url disable`, and never CNAME your own hostname to the `r2.dev` address, which is an unsupported path.
code
bash · 4 linesnpx wrangler r2 bucket domain add thumbnails --domain thumbs.example.com --zone-id <ZONE_ID>
npx wrangler r2 bucket domain list thumbnails
npx wrangler r2 bucket dev-url disable thumbnails
npx wrangler r2 bucket dev-url get thumbnailsgo deeper
Recall that buckets are private by default, that r2.dev is for testing, and that production traffic goes through a custom domain on your own zone.
Explain why r2.dev fails in production: a variable rate limit with 429s and no cache, WAF or Access, and how a custom domain from the same account changes that.
Show you close the side door: disable r2.dev after protecting the custom domain, keep private originals in another bucket, and expect cached copies to outlive overwrites.
Decide where public access is allowed at all: which buckets may ever be public, who may enable a development URL, and how that rule is checked across accounts.
## Two ways to make a bucket public An R2 bucket is **private by default**: only authenticated access, such as a Worker binding or signed S3 API requests, can read it. **Public access** serves objects to anyone with an HTTP client, read-only, and comes in two forms that are switched on independently. | | Public development URL (`r2.dev`) | Custom domain | |---|---|---| | Intended for | testing and development | production traffic | | Hostname | a Cloudflare-managed `r2.dev` subdomain | a hostname on your own zone | | Rate | variable rate limit; 429s and throttled bandwidth | no `r2.dev` limit | | Cache, WAF, Access, Bot Management | not available | available | | Egress charge | none | none | Either way the bucket's contents are not listable at the domain root: a public bucket serves an object by key, not a directory index. ## Why r2.dev is only for development The `r2.dev` endpoint lets you see objects in a browser minutes after creating a bucket, and that is its whole purpose. - It carries a **variable rate limit**. Past roughly hundreds of requests per second, R2 throttles it and returns `429 Too Many Requests`; bandwidth can be throttled too. - It sits outside your zones, so **none of your zone settings** apply: no cache, no WAF custom rules, no Access policy, no Bot Management, no per-URL analytics. - Pointing a CNAME from your hostname at the `r2.dev` address is an **unsupported access path** with no guarantee of reliability or performance. A thumbnail grid that loads 40 images per page view reaches that rate with a modest audience, which is why the limit shows up in production first. ## Connecting a custom domain 1. Make sure the domain is a **zone in the same Cloudflare account** as the bucket. A domain whose DNS lives elsewhere can be added with a partial (CNAME) setup. 2. Connect it in the bucket's settings or with `wrangler r2 bucket domain add <bucket> --domain <hostname> --zone-id <zone-id>`, optionally with `--min-tls`. 3. R2 creates the DNS record and activates the hostname; a bucket can carry up to 100 custom domains. 4. Disable the development URL with `wrangler r2 bucket dev-url disable <bucket>` once traffic has moved. ## What changes once a domain fronts the bucket - **Caching** becomes possible, so repeated thumbnail reads can be answered from Cloudflare's cache instead of becoming R2 Class B operations. Which files are cached, and for how long, is a cache-rules decision covered with Cloudflare's caching settings. - **Security rules** apply: WAF custom rules, rate limiting, Bot Management, or an Access policy for a bucket only staff should read. - **Consistency is relaxed for cached reads.** The binding and the S3 API always see the latest object, but a cached copy of an overwritten or deleted thumbnail keeps being served until it expires or is purged, which is why many teams write a new key for each thumbnail version. - **CORS** headers from the bucket's CORS policy are returned on the custom domain for cross-origin requests that send an `Origin` header. ## Mistakes that leave the bucket exposed or fragile - Adding WAF rules or Access to the custom domain while `r2.dev` stays enabled: anyone who knows the development URL bypasses every rule. - Putting private originals in the same bucket as public thumbnails. Public access is a **bucket-level** switch, so originals belong in a second, private bucket read through a Worker binding or presigned GET URLs. - Expecting presigned URLs to work on the custom domain; they work only on the S3 API endpoint. - Treating `r2.dev` as free load testing; its limit says nothing about how the custom domain will behave. ## When the bucket should not be public at all Public access suits objects anyone may fetch by URL, such as thumbnails with unguessable keys. When reads need a check, such as a private album or a paid course video, keep the bucket private and put a Worker in front: it authenticates the viewer, calls `env.BUCKET.get()` through the binding, copies `httpMetadata` with `writeHttpMetadata()`, and streams the body. R2 charges no egress for the bytes the Worker reads and returns.
- A team puts an Access policy on its R2 bucket's custom domain, yet strangers still load the files. Why?The custom domain and the `r2.dev` URL are independent ways in. Access, WAF and Bot Management protect only the custom domain, so a bucket whose development URL is still enabled stays readable at `r2.dev`. Disabling it with `wrangler r2 bucket dev-url disable` closes that path.
- In R2, how do you keep video originals private while their thumbnails are public?Use two buckets, because public access is switched on per bucket. The thumbnails bucket gets a custom domain; the originals bucket stays private and is read by a Worker through its binding after checking the viewer's session, or through short-lived presigned GET URLs on the S3 endpoint.
- r2.dev is fine for production as long as traffic stays modest
- Connecting a custom domain automatically disables the r2.dev URL
- Serving from r2.dev costs egress while a custom domain is free
- A public R2 bucket lists its objects at the domain root
- A CNAME to the r2.dev hostname is a supported production setup