Cloudflare worker反代 实现镜像站

效果

反代前, 访问 https://zelikk.blogspot.com/1.html
得到

<html>
  <body>
    <a href="https://zelikk.blogspot.com/2.html">Page2</a>
    <img src="https://blogger.googleusercontent.com/3.jpg">
  </body>
</html>

反代后, 访问 https://one.eu.org/1.html
得到

<html>
  <body>
    <a href="https://one.eu.org/2.html">Page2</a>
    <img src="https://img.one.eu.org/https://blogger.googleusercontent.com/3.jpg">
  </body>
</html>

思路

用1个worker反代图片 用成熟的uniporxy项目

用1个worker反代html (即本项目)
并对html内容进行替换

项目

部署方法

示例,
想反代的域名是 zelikk.blogspot.com
镜像站的主域名是 one.eu.org 并且已经添加到 cloudflare

那么, 步骤如下:

域名 one.eu.org 设置自动TLS

建第1个worker

名称 例如, blogimg
自定义域名 img.one.eu.org
代码 使用成熟的uniporxy项目

建第2个worker

名称 例如, bloghtml
自定义域名 one.eu.org
代码 使用本项目的worker.js
代码开头的部分, 设置一些参数

部署完成

你可以用浏览器访问镜像站 https://one.eu.org

如果你想屏蔽部分path

就是说有一些原网站的页面, 你不希望在镜像站展示.

建1个KV

名称 例如, bloghtml_blocklist
添加
key = 你不想显示的path 如 /2023/06/racknerd-xray-reality.html
value = block

绑定KV

bloghtml worker 绑定KV
name KV_BLOCKLIST (不要改动)
value bloghtml_blocklist (就是前面步骤中建立的KV名字)

如果你觉得要一条一条的添加需要屏蔽的path太麻烦了. 如果你有自定义博文链接的习惯的话. 你还可以根据path中的关键字来进行屏蔽.

根据关键字屏蔽path

修改bloghtml worker的代码
数组 BLOCK_KEYWORDS 中添加你想屏蔽的path关键字.

我项目中的逻辑是, 根据path中的关键字来判断是否屏蔽. 如果你觉得需要根据html整个内容进行关键字屏蔽, 问问GPT, 修改方案应该很容易.

22 个赞

感谢大佬!

1 个赞

反代违反协议来着?
自己用用还好,建议不要公开放出来说是

1 个赞

大佬能不能逆向一下这个项目,源文件被混淆了
https://github.com/netptop/siteproxy

1 个赞

真优质啊

2 个赞

cf欺诈警告 :rofl:

2 个赞

学习一下

1 个赞

现在反代容易被封号说是

这个是反代啥的 :open_mouth:任意网站吗

1 个赞

厉害了 大佬

1 个赞

看上去是的.

你注意阅读一下 worker.js 文件头部的几个参数.

1 个赞

CF封号警告:warning:

1 个赞

可以试试反代GitHub

1 个赞

反代的人为自己的行为负责.

有些人是有自己的反代需求的.
比如, 把自己墙外的博客反代到墙内.

Cannot read properties of undefined (reading ‘get’)

有更详细的信息吗?

我自己的反代活得好好的.

算了,我已经删掉了

1 个赞

[!tip] 纯纯的技术分享~