Skip to content
A2Z Skills
Topics
Search

Cloudflare Workers custom domain not working

Devchandra Shrestha

6 min read

Short answer

A Workers custom domain only attaches to a Cloudflare zone that is active and reachable from the Worker’s account. In this test the zone stayed pending until the registrar’s nameservers changed, and the first deploy failed because the account had no workers.dev subdomain yet.

Tested 25 October 2026 by Devchandra Shrestha

wrangler
4.152.0
Node.js
26.11.1
macOS
27.2
Device
Mac, Apple silicon
A cloud and domain globe separated by an unconnected cable.
Editorial illustration

Adding a domain to Cloudflare and having a Worker answer on it are two different states. Four things sit between them, and each one reports itself in a way that points somewhere else. We hit all four in an afternoon putting a static site on Workers, which is the sort of job the websites and hosting guides cover.

Identify which part is failing

A Worker can answer on its workers.dev address while the custom hostname still fails. DNS, the zone’s account and status, and the Worker attachment are separate checks. This guide records the cases encountered during the deployment named in the test box.

Observation Relevant section
The zone is absent from the Worker’s account Check the zone and account
The zone is present but pending Compare the nameservers
No workers.dev address is available Create the account’s Workers subdomain
Login fails before deployment starts Read the OAuth/session section

A DNS record’s cache lifetime is a separate question from whether the Worker has a valid domain attachment. The DNS propagation explanation covers that difference.

Current Cloudflare documentation also describes hostname prerequisites and other failure cases. A 522 response or an existing-record conflict needs its own diagnosis; neither is proof that the nameservers are wrong. Those cases are not claimed as reproduced by the test record on this page.

Check the zone is on the same account first

A Workers custom domain needs the domain’s zone to live on the same Cloudflare account as the Worker. Pointing DNS at Cloudflare is not the same thing. The zone must also be active. This test used Cloudflare’s full DNS setup, in which the registrar delegates to Cloudflare nameservers. Cloudflare’s partial setup has different prerequisites; a full-zone test is not evidence for every setup.

Check that before you deploy:

  1. List the zones on the account

    In the dashboard, Websites shows every zone on the account. If the domain is not in that list, a custom_domain route in wrangler.json cannot work. We took ours out rather than watch the deploy fail on it.

  2. Look at the status, not just the name

    A zone that has been added but never pointed at Cloudflare sits at pending. Pending is not active: the registrar’s nameservers still answer for the domain, so nothing you deploy is reachable on it.

  3. Compare the nameservers

    Cloudflare gives each zone a pair, such as gloria.ns.cloudflare.com and margo.ns.cloudflare.com. Compare them with what the domain actually publishes:

    dig +short yourdomain.com NS

    If that comes back with your registrar’s own nameservers, the change has not been made, or has not propagated yet.

Deploy to workers.dev while the zone is pending

A Worker with workers_dev enabled gets a URL straight away, so there is no need to wait for DNS before testing the real build. Keep that URL out of search results, though, or it will compete with your own domain for the same pages. In public/_headers:

https://:version.:subdomain.workers.dev/*
  X-Robots-Tag: noindex

We read the response header back off the live deploy to check: it returned x-robots-tag: noindex on the workers.dev host. The rule matches that hostname only, so the custom domain is unaffected once it exists.

Fix the login error that mentions cookies

Before any of that, wrangler login can fail in a way that reads like a Cloudflare outage:

✘ [ERROR] OAuth error: request_forbidden
    The request is not allowed. No CSRF value available in the session cookie.

In this session the problem was the browser’s Cloudflare login state. Using an authenticated browser resolved it. The message alone does not prove that every account or OAuth configuration is otherwise correct.

Pick the browser yourself:

npx wrangler login --browser=false

That prints the authorisation link instead of opening it. Sign in to dash.cloudflare.com in the browser you want to use, paste the link there and approve it. wrangler whoami then reports the account.

Create the workers.dev subdomain if the account has never had one

On an account where Workers has never been opened there is no workers.dev subdomain at all, and the API says so if you ask it directly:

HTTP 404: 10007: You do not have a workers.dev subdomain.
Opening the Workers & Pages landing page for the first time will create a
workers.dev subdomain automatically

Visiting that dashboard page once creates it. To choose the name instead, set it over the API:

curl -X PUT "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/subdomain" \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{"subdomain":"yourname"}'

It is account-wide, and every Worker URL on the account is built from it, so pick a name you can live with.

Once the zone is active, add the route and redeploy

With the zone active, put the route back and deploy again:

{
  "routes": [{ "pattern": "yourdomain.com", "custom_domain": true }],
}

Waiting on the zone is a separate question from waiting on a record, and the second one is explained in DNS propagation: cached answers use their earlier TTL, while provider publication, delegation and exceptional cache behaviour can also affect the delay.

The same split shows up when self-hosting: in self-host n8n on Coolify the platform and the application each hold their own copy of the hostname, and both have to be told.

Attaching a Custom Domain does not by itself configure a www redirect to the apex. This setup handled that separately with a Cloudflare Redirect Rule. And _redirects and _headers do work on Workers static assets, which a lot of advice still treats as a Pages-only feature; the limits are 2,000 static redirects, 100 dynamic ones and 100 header rules.

What broke while testing

Three things went wrong, none of them documented where we were looking.

The CSRF error above cost the most time. It names cookies, so it reads like a Cloudflare fault, when the cause is the session in the browser.

The missing workers.dev subdomain only surfaced when we queried /workers/subdomain directly. Deploying without noticing would have left a Worker with no reachable URL.

The asset upload also failed part way through and recovered on its own. On a deploy of 68 files, wrangler printed:

Uploaded 46 of 68 assets
Asset upload failed. Retrying... 1 of 5 attempts.
Uploaded 68 of 68 assets
✨ Success! Uploaded 68 files (31.49 sec)

That is wrangler’s own retry doing what it is there for. Worth seeing once before you meet it in CI and cancel a deploy that was going to succeed.

What to check at the end

Four commands tell you whether it worked, and they are quicker than clicking through the dashboard:

curl -s -o /dev/null -w '%{http_code}\n' https://yourdomain.com/
curl -s -o /dev/null -w '%{http_code} -> %{redirect_url}\n' https://yourdomain.com/about
curl -sI https://yourdomain.com/ | grep -i x-robots-tag
dig +short yourdomain.com NS

The second should show a 307 to the trailing-slash form if you set html_handling to force-trailing-slash. The third should return nothing on the real domain. In this full-zone setup, registrar nameservers indicated that the intended delegation was not visible through the resolver queried. Other zone setups need their own checks.

A separate origin server

For a traditional website proxied to a server, Cloudflare SSL modes explains Flexible, Full and Full (strict). That origin connection differs from serving a Worker directly on its Custom Domain.

Two Worker-specific error cases are documented elsewhere by Cloudflare. A Worker on a Custom Domain that performs a fetch to its own hostname returns a 522, explained in Cloudflare error 522. A Workers subrequest into a partial, CNAME setup zone with no record for the hostname returns a 1016, explained in Cloudflare error 1016.

Sources

ShareHacker News

Did this fix it?

We re-test the guides that stop working. Telling us is the fastest way to get one fixed.

Questions people also ask

Do I have to move my whole domain to Cloudflare just to use a Worker?
The recorded full-zone setup required changing the registrar’s nameservers. Cloudflare also documents other zone setups with different prerequisites. A Worker route is not a universal workaround for an inactive or unsupported zone; check the setup that applies to your account.
How long does the zone stay pending after I change nameservers?
Cloudflare rechecks periodically and you can trigger a check from the dashboard. In our experience it is minutes rather than hours, but registrars publish nameserver changes on their own schedule, so plan for it to be slow rather than instant.
Is a workers.dev URL safe to leave up once the real domain is live?
It is, as long as it is not indexable. A _headers rule matching the workers.dev host with X-Robots-Tag: noindex keeps it out of search results so it cannot compete with the real domain for the same content.
Why did my first deploy say the Worker had no subdomain?
Because the account had never had Workers opened on it. A workers.dev subdomain is created the first time you visit Workers & Pages in the dashboard, or you can set the name directly over the API.

Devchandra ShresthaEditor, A2Z Skills

I run A2Z Skills and edit everything that goes out. My own testing is desktop and web: Windows and macOS repair, domains, DNS and hosting. If a step in one of our guides does not work on your machine, I am the one who reads the email and fixes the post.

Join the guide notification list

Email delivery is not active yet. No sharing or selling your address.