Serving S3 folders based on subdomain

I’m lost here, been looking everywhere for a solution - not sure if its possible (through DNS).

I want to host static websites (through Backblaze B2, or S3) for my users. Each user’s site (all the html, css, js etc) will be within a folder on the bucket. They will then get a custom subdomain that I want to map to these buckets.

For example, a user uses my site, they are given a subdomain of

which will point to

Now I’ve done this with a worker’s script, where the script gets the subdomain and then returns the updated URL. The worker is routed through based on **, and I have a wildcard CNAME record on that points to the workers script.

When I myself access in my browser, it all works and the HTML file is returned. But when I add a CNAME to a different domain on Cloudflare, say, that points to I get a 522 error.

I don’t understand how I can access the domain, but when pointing to it from another domain with a CNAME it doesn’t work.

Is this the right approach for something like this?

Hi @user4389,

It sounds like you want something like this:

Essentially you can’t just point a CNAME at a hostname without that hostname being configured to respond to that.

Thanks, domjh, in the midst of the frantic research I did into this problem this morning, I did come across these solutions, but looks like they are still in beta?

Thanks for the answer though, I guess I’ll try signing up and see if it fits my needs.

I’m not sure what its beta status is. Though at the moment, I can’t add a Worker (or Page Rule) to match the hostname of an “add-on” domain. I get the usual “You need to include MYDOMAN in the hostname.” Meaning only the current zone’s domain, not a SaaS domain.

I have a ticket open on this and they’re working on it. Dom already knows this works on full-blown Enterprise SaaS plans, but it hasn’t trickled down to the SaaS For Everyone feature.

1 Like

Looks like I may have to look into either handling requests through an nginx instance or use Cloudfron with S3 and Lamba’s on the edge, as per: amazon web services - Serving a multitude of static sites from a wildcard domain in AWS - Stack Overflow

If you go to the SSL section on the dashboard for your domain, and click custom hostnames its there (costs $2/month per hostname). Haven’t tested it for my use case but thought I’d let you know!

Oh, I did that, and the site works, but Page Rules and Workers are tripping me up.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.