基于Cloudflare实现api.open.com的代理访问
开发/后端文章 · 阅读 2945 · 点赞 1
Cloudflare 是一个全球网络,旨在让您连接到互联网的一切都安全、私密、快速和可靠。
- 保护您的网站、API 和互联网应用程序。
- 保护企业网络、员工和设备。
- 编写和部署在网络边缘运行的代码。
偶然间看到有人发了这样一条Twitter

于是按照他的提示尝试操作,先把操作步骤详细阐述下
- 注册并登录到 Cloudflare 账户


注册很简单,邮件注册即可。
2. 创建一个新的 Cloudflare Worker


选择 http handler即可,然后点击create service。回到列表点击刚才创建好的的worker,将 cloudflare-worker.js 复制并粘贴到 Cloudflare Worker 编辑器中,这时候需要用到前台代码,码直接用其他人写好的 https://github.com/barretlee/cloudflare-proxy


最后点击 Save and deploy 。
3. 在 Worker 详情页 -> Trigger -> Custom Domains 中为这个 Worker 添加一个自定义域名


这时候最好是使用在 cloudflare上注册的域名,(其他的域名也是可以,只是需要讲域名托管到cloudflare,方法也很简单),目前我为了省事,是直接在cloudflare上注册购买域名,然后使用。

4.到目前 cloudflare 的部分就完成了 ,接下来就是验证好用不好用的阶段
目前我的电脑是安装了梯子并开启了,直接使用域名api.openai.com是正常的,如下图

如果我把梯子关掉,继续使用api.openai.com访问就无法访问成功,如下图

此时我继续保持关闭梯子的条件下,使用cloudflare代理域名访问,如下图

目前看是cloudflare代理域名是成功的,再来看下刚才的访问的记录,可以看到cloudflare监控中的访问记录。
