Worker returns 521 Origin Down when connecting to custom port on gray-cloud domain in my zone

According to this thread it should be working and yet I’m having the error.

So my setup is like this:

I have a gray-cloud A record my.domain.com in my Cloudflare zone pointing to my server IP.
The server is listening at port 8080 that serves a HTTP website.

On my local machine, I verified the HTTP server is live, and the DNS is working, by doing this:

curl http://my.domain.com:8080/

And it returns the page successfully.

Then I setup my Worker script like this:

addEventListener('fetch', event => {
  event.respondWith(fetch('http://my.domain.com:8080/'))
})

If I run the script in the online editor, it works and renders the page successfully inside the editor environment.
However if I publish the Worker, and access it from my local machine:

curl https://myworker.workers.dev/

Then it returns 521 Origin Down error.

I tried several things and it seems only port 80 is working for the published Worker, while any arbitrary port works inside the online editor environment.

My goal is to use port 8080 in the published Worker script. Please advise how can I get it working.

1 Like