Error 1003: A valid Host header must be supplied to reach the desired website

I am trying to access a website ( with fetch in a worker, however I am getting this error, which is supposed to appear when I try to access an IP directly, which is not the case:

With other sites it works correctly.

Here is the code I use:

addEventListener('fetch', event => {

async function forwardReq(request) {
  const init = {
    body: request.body,
    headers: request.headers,
    method: request.method,
  let response = await fetch ('', init);
  return new Response(response.body, {
    status: response.status,
    statusText: response.statusText

What am I forgetting?

Edit: when I test in the development environment I get a 502 error, “Error communicating with origin server localhost”. It looks like it points to localhost instead of the site:

Also, if I test just the domain without any path, it works, but the rest of the urls don’t work. For example, “” does not work, but “” works.

I think for security reasons you can only fetch from domains in your own account which means you have to add an A record with their IP, but that defeats the whole purpose of using Cloudflare.

Loads for me, are you sure your not access a cloudflare IP by mistake?

I’m sure. When I test here it also fails, but with another error, it seems to point to localhost instead of the site:

With other sites there are no problems:

Then why can I use it with other sites?

I am doing this: How to bypass CloudFlare bot protection ? | by jychp | Medium

This topic was automatically closed after 29 days. New replies are no longer allowed.