R2 "Allow Domain" conflicts with Cloudflare Pages CNAME?

Hi everyone,

Working on a new project and just discovered Cloudflare pages and R2 storage. Amazing!

Now I’m having an issue because when I want to allow my domain to serve the content of my bucket, it’s trying to take the WWW CNAME:-1:

See screenshot

Any ideas how to solve this?

1 Like

I’m not too sure what you mean. You can’t have both a Pages project and R2 public buckets using the same domain. In this case it looks like you’re trying to do that with your www subdomain

So you mean when it’s asking which domain to allow, I could type:
example.com or audio.example.com rather than
www.example.com?

and I would be able to serve the content of my bucket from www.example.com?

Yes, you can type whatever domain you want. Wherever you want the content served, write that in.

Yes but then your Pages project won’t serve there.

That’s my problem. I want to use r2 to have a bunch of audio files that I want to serve on my website www.example.com.

But for that I need to Allow Domain. But I can’t it seems since the CNAME comes into conflict.

You would need to use different domains or use Pages Functions to fetch from R2 instead. Pages and R2 can’t live on the same domain (how would it know what to fetch from where?)

1 Like

Thanks for your patience @Walshy . But I have to be honest, this doesn’t make sense.
There is a public url where the R2 Bucket lives: https://xxxxxxxxxxx.r2.dev
where I turned on " Public Access: Allowed"

Now all I need is to allow my website to fetch from it:

Domain Access

When Domain access is Allowed, websites can serve content from this bucket. Websites connected can also benefit from Cloudflare features such as bot management, Access, and Cache.


Doesn’t that just mean that I can allow www.example.com to serve the content that is found in my bucket found on https://xxxxxxxxxxx.r2.dev?

alright…I think I understand you now. I misunderstood what domain access meant. I thought it was along giving access to fetch from a particular domain.

Thanks for you time…and patience.

Hi renaudgagne I am new to using Cloudflare and ran into the same problem as you. I’m curious what you ended up doing here? Did you just use the r2.dev public urls?

My current understanding is that it’s not possible to both serve a page on a domain AND use that domain for a custom R2 bucket. For instance if I want to link my build to www.example.com, I can’t also run an R2 bucket connected to www.example.com. I have to either use the public domain feature or use a different domain that I own to serve the bucket contents.

Never mind. I found a nice solution to this which is to simply create a CNAME subdomain (e.g. media.example.com) and link that as the custom R2 bucket :slight_smile: