今天我 CF Workers 反代的博客突然炸了。

报错 1021 ,另一个短链 Workers 也一样。
img_3984.jpg

错误1021:未找到网站。
我试图自己解决问题和搜索解决方法,但很奇怪的是,这个错误像个新生儿,上哪都找不到解决方案。而且,我另一个域名的反代是没问题的。这让我十分纳闷儿。

直到我到 Community 搜索 1021 ,终于,发现了如下帖子:

https://community.cloudflare.com/t/workers-recently-receiving-error-code-1021-when-fetching-3rd-party-website/250112/3

这令我虎躯一震,看来我不是一个人。帖中有网友写道:

This issue could be because i did something dumb, but: When you set up CF pages and use your main domain as a custom domain for CF Pages, AND you use your main domain with workers and set up subdomain for your worker scripts, it wont break workers IE, it wont stop you from requesting your worker but it broke some fetch() calls to external sites such as GitHub, i was getting the http code of 409. removing my main domain name from CF Pages fixed this issue. Im sure i can repeat this issue if needed. Just thought id put this here if someone else has a similar issue.
这个问题可能是因为我做了一些蠢事,但是:当你设置 CF 页面并将主域用作 CF Pages 的自定义域时,以及您将主域与 Workers 一起使用并为您的 Workers 设置子域时,它不会断绝您请求您的 Workers,但它打破了对 GitHub 等外部网站的一些获取调用,我收到了 409 的 http 代码。我从 CF Pages 中删除了我的主域名,修复了此问题。如果需要,我相信我可以重复这个问题。只是想如果别人有类似问题,我就把这个放在这里。

可以预见,此番 1021 报错,也很有可能与 CF Pages 有关。

帖子作者写道:

In case someone having the same issue, please remove the CNAME and set up a page rule to redirect your {domain}.com to www.{domain}.com as a workaround.
如果遇到相同问题,请删除(主域) CNAME 并设置页面规则,将您的 {domain}.com 重定向到 www.{domain}.com> 作为变通办法。

我这才想起来,出现问题的时候,我恰巧设置完 CF Pages。

解决方案

  1. 添加一条页面规则,内容如下:
    image-1024x162.jpg

301 www.example.com/* 到 http(s)://example.com/$1

  1. 删除根域到 Pages 的解析。
    image-1.jpg
  2. 转到 CF Pages ,删除到根域的路由。
    image-2.jpg

再次打开 Workers 反代,唉嘿,解决啦!

写在最后

经过一番折腾,问题是解决了,但十分地曲线救国。

这个问题的出现,我想是 Cloudflare 不曾预料的—— Beta 产品,可以理解。

但我希望这个问题不会持续太久。由于技术和精力有限,我没办法深入研究这个问题,只给大家提供一种有效的临时方法。我也将把问题反馈给 Cloudflare 团队。希望问题早日解决,我能重新用回主域。

文章目录