Skip to content
On this page

EDtunnel

ed哥哥

GitHub Repository for https://github.com/zizifn/edgetunnel

Repository

Deploy in pages.dev

  1. See YouTube Video:

    https://www.youtube.com/watch?v=8I-yTNHB0aw

  2. Clone this repository deploy in cloudflare pages.

Deploy in worker.dev

  1. Copy _worker.js code from here.

  2. Alternatively, you can click the button below to deploy directly.

    Deploy to Cloudflare Workers

Lazy to deploy

aHR0cHM6Ly9vc3MudjJyYXlzZS5jb20vcHJveGllcy9kYXRhLzIwMjMtMDYtMjAvZFFOQTk3LnlhbWw= (clash config)

UUID Setting (Optional)

  1. When deploy in cloudflare pages, you can set uuid in wrangler.toml file. variable name is UUID.

  2. When deploy in worker.dev, you can set uuid in _worker.js file. variable name is userID.

UUID Setting Example

  1. single uuid environment variable

    .environment
    UUID = "uuid here your want to set"
  2. multiple uuid environment variable

    .environment
    UUID = "uuid1,uuid2,uuid3"

    note: uuid1, uuid2, uuid3 are separated by commas,. when you set multiple uuid, you can wiill use https://edtunnel.pages.dev/uuid1 to get the clash config and vless:// link.

  1. visit https://edtunnel.pages.dev/uuid your set to get the subscribe link.

  2. visit https://edtunnel.pages.dev/sub/uuid your set to get the subscribe content with uuid your set path.

    note: uuid your set is the uuid you set in UUID enviroment or wrangler.toml, _worker.js file. when you set multiple uuid, you can wiill use https://edtunnel.pages.dev/sub/uuid1 to get the subscribe content with uuid1 path.(only support first uuid in multiple uuid set)

  3. visit https://edtunnel.pages.dev/sub/uuid your set/?format=clash to get the subscribe content with uuid your set path and clash format. content will return with base64 encode.

    note: uuid your set is the uuid you set in UUID enviroment or wrangler.toml, _worker.js file. when you set multiple uuid, you can wiill use https://edtunnel.pages.dev/sub/uuid1/?format=clash to get the subscribe content with uuid1 path and clash format.(only support first uuid in multiple uuid set)

multiple port support (Optional)

For a list of Cloudflare supported ports, please refer to the official documentation.

By default, the port is 80 and 443. If you want to add more ports, you can use the following ports:

text
80, 8080, 8880, 2052, 2086, 2095, 443, 8443, 2053, 2096, 2087, 2083
http port: 80, 8080, 8880, 2052, 2086, 2095
https port: 443, 8443, 2053, 2096, 2087, 2083

if you deploy in cloudflare pages, https port is not supported. Simply add multiple ports node drictly use subscribe link, subscribe content will return all Cloudflare supported ports.

proxyIP (Optional)

  1. When deploy in cloudflare pages, you can set proxyIP in wrangler.toml file. variable name is PROXYIP.

  2. When deploy in worker.dev, you can set proxyIP in _worker.js file. variable name is proxyIP.

note: proxyIP is the ip or domain you want to set. this means that the proxyIP is used to route traffic through a proxy rather than directly to a website that is using Cloudflare's (CDN). if you don't set this variable, connection to the Cloudflare IP will be cancelled (or blocked)...

resons: Outbound TCP sockets to Cloudflare IP ranges are temporarily blocked, please refer to the tcp-sockets documentation

Usage

frist, open your pages.dev domain https://edtunnel.pages.dev/ in your browser, then you can see the following page: The path /uuid your seetting to get the clash config and vless:// link.

Star History

Star History Chart

An article about the project

Note: This article is fully written by GPT-4

项目背景

众所周知,V2Ray 是目前科学上网领域使用最广泛的开源项目之一。它支持众多传输协议,其中 VLESS 协议以其简单高效而深受用户喜爱。但是 V2Ray 本身比较难以部署使用,这给不少用户带来了麻烦。

作为一个云计算技术爱好者,我觉得可以试试使用 Cloudflare Workers 来实现一个 VLESS 配置和订阅服务。Workers 是一个无服务器平台,部署非常简单,而且可以实现全球 CDN 加速。我相信这可以让用户获得更好的科学上网体验。

实现原理

这个项目的核心就是以下几个步骤:

  1. 用户发起请求访问 Worker

  2. Worker 根据路径判断是配置输出还是订阅输出

  3. 对于配置输出,根据用户的 UUID 生成 VLESS 链接

  4. 对于订阅输出,遍历各种端口,生成包含多条 VLESS 链接的订阅内容

  5. 输出响应,用户获得配置或订阅链接

  6. 用户配置代理软件,通过 VLESS 链接完成代理

这里主要用到了 Cloudflare Workers 的 Fetch API 来发起请求,获取响应等。同时也用到了文本处理能力,拼接生成所需的 VLESS 配置和订阅内容。

使用指南

使用这个 Worker 生成 VLESS 配置非常简单,只需要以下几步:

  1. 部署 Worker 代码,记下分配的域名

  2. 用户访问 yourdomain/UUID 获取默认 IP 的配置

  3. 访问 yourdomain/sub/UUID 获取订阅链接

  4. 在代理软件中添加订阅或配置,即可开始科学上网!

另外,Worker 支持传入环境变量,可以连接数据库获取用户信息等,功能十分强大。

您提醒我着重介绍一下处理 VLESS 请求的代码部分,我重新调整了一下文章内容,着重写了这一部分:

处理 VLESS 请求

处理 VLESS 请求是这个 Worker 的核心所在。当用户请求不同的路径时,Worker 需要分情况处理:

配置输出

如果路径是 /UUID,则是获取配置。此时需要:

  1. 根据用户 UUID 生成 VLESS 链接模板

  2. 填充主机名、路径等信息

  3. 输出 VLESS 配置给用户

这里用到了模板字符串的方法,根据用户信息动态生成配置,代码如下:

js
function getVLESSConfig(userIDs, hostName) {
  // 生成每个用户的 VLESS 配置
  userIDs.forEach((userID) => {
    const template = `vless://${userID}@${hostName}:443?encryption=none#${hostName}`;

    // 填充具体信息
    const vlessLink = template
      .replace("${userID}", userID)
      .replace("${hostName}", hostName);

    // 输出配置
    output.push(vlessLink);
  });

  return output.join("\n");
}

订阅输出

如果路径是 /sub/UUID,则是获取订阅。此时需要:

  1. 遍历各种端口(80、443 等)

  2. 为每个端口和用户生成多个 VLESS 链接

  3. 拼接为符合订阅格式的输出

这里用到了两个循环嵌套的方式生成了大量链接,再拼接为输出,代码如下:

js
function createVLESSSub(userIDs, hostName) {
  const ports = [80, 443];

  const output = [];

  ports.forEach((port) => {
    userIDs.forEach((userID) => {
      const vlessLink = `vless://${userID}@${hostName}:${port}?encryption=none`;

      output.push(vlessLink);
    });
  });

  return output.join("\n");
}

可以看到,通过简单的模板和拼接,就可以动态输出所需的 VLESS 配置和订阅。这为用户提供了极大的便利。

其他部分就不赘述了,有兴趣的可以去我的 GitHub 上查看完整代码。欢迎提意见,让我们共同进步!

上次更新于: