522 error when accessing worker via CNAME

I’d like my customers to be able to “white label” my SaaS app - in other words, point their domains to a Cloudflare worker via a CNAME record.

Cloudflare For SaaS products should provide for this, but when I access the worker via a C NAME rather than directly, I get a 522 error.

Steps taken so far

1.) Launched a worker (“myco-cnames”) and assigned it the route “customer” under my main company domain. When I access this directly, it is providing a response correctly.

2.) Added this as the fallback origin under SSL/TLS / Custom Hostnames on Cloudflare.

3.) Added a custom hostname matching the customer’s whitelabel sudomain on Cloudflare. Both the SSL/TLS certificate status and the Hostname status are currently Active.

4.) Added a CNAME at the customer’s registrar to point to the customer route under my main domain.

Expected behaviour

When navigating to the customer’s subdomain, I expect to see the C NAME work, and display the content from the worker.

Actual behaviour

I see a “Connection timed out” error, 522 code.

Additional info

1.) I saw another customer had the same issue (ID 329219). I didn’t add any AAA records, as don’t understand if that is relevant.

2.) The worker works fine when accessed directly, i.e. not via a C NAME

3.) The worker is configured with the simplest example from Cloudflare possible and should return a simple HTML file.

4.) Myco doesn’t exist; this is in place of my company’s name. I can’t add links due to privileges.

Filed as support ticket with actual domain info: 2938629.

Welcome to the Cloudflare Community!

There’s a specific way you have to setup your Worker Routes to make CF for SaaS/Custom Hostnames work with Workers:

You basically just need a wildcard route to match all traffic - including those from custom hostnames. Worker Routes doesn’t see the traffic as yourworkerfallbackdomain.example.com, it sees it as from your customer’s custom hostname. Just be careful to exclude other subdomains if you use that domain for other things, as per the guide.

1 Like