跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com

快速隧道

最后更新 查看 MarkdownAgent 设置

快速隧道为本地服务创建临时的 trycloudflare.com URL。您不需要 Cloudflare 账户或域。

先决条件

  • 安装 cloudflared。
  • 启动本地 HTTP 服务器。本示例使用 http://localhost:8080。

创建快速隧道

  1. 在终端中启动快速隧道:

    cloudflared tunnel --url http://localhost:8080
  2. 打开 cloudflared 打印的 trycloudflare.com URL。

任何持有该 URL 的人都可以访问您的本地服务。当您停止 cloudflared 进程时,该 URL 将停止工作。

按电子邮件限制访问

使用 --allowed-mail 要求进行电子邮件身份验证。访问者在访问您的服务之前会收到一次性 PIN。

  1. 使用允许的电子邮件地址启动快速隧道:

    cloudflared tunnel --url http://localhost:8080 --allowed-mail [email protected]
  2. 将生成的 URL 分享给获准的访问者。

  3. 访问者打开该 URL 并输入其电子邮件地址。

  4. 访问者输入发送到其电子邮件的一次性 PIN。

访问者不需要 Cloudflare 账户。

重复该标志

重复 --allowed-mail 以允许多个电子邮件地址:

cloudflared tunnel --url http://localhost:8080 \
  --allowed-mail [email protected] \
  --allowed-mail [email protected]

使用逗号分隔列表

用逗号分隔多个电子邮件地址:

cloudflared tunnel --url http://localhost:8080 \
  --allowed-mail '[email protected],[email protected]'

允许某个电子邮件域

使用 *@example.com 允许来自某个域的所有地址。将通配符值放在引号中,以防止 shell 展开:

cloudflared tunnel --url http://localhost:8080 --allowed-mail '*@example.com'

若要更改谁可以访问该服务,请停止 cloudflared 并启动一条新的快速隧道。进程停止后,所有人的访问都会结束。

限制

  • 快速隧道没有正常运行时间保证。
  • 每条快速隧道最多支持 200 个进行中的请求。额外请求会返回 429 响应。
  • 快速隧道不支持服务器发送事件 (SSE)。
  • 电子邮件身份验证需要交互式浏览器会话。它不支持非交互式客户端。
  • 每次创建快速隧道时,主机名都会变化。

对于稳定主机名和生产流量,请创建 Cloudflare Tunnel。

这篇文档对您有帮助吗?