使用 Cloudflare Tunnel内网穿透

503 阅读1分钟

使用 Cloudflare Tunnel 将本地应用程序暴露到互联网的简明教程:

使用 Cloudflare Tunnel 的简明教程

步骤 1:下载和安装 cloudflared

  • macOS(使用 Homebrew)

    brew install cloudflared
    
  • Windows 或 Linux: 从 Cloudflare GitHub 仓库 下载最新版本并按照说明进行安装。

步骤 2:认证 cloudflared

运行以下命令以认证:

cloudflared tunnel login

此命令将打开一个浏览器窗口,提示您登录到您的 Cloudflare 帐户。 -登陆后选择你要穿透的域名,比如 example.com

image.png

步骤 3:创建隧道

创建一个名为 5173名字可以是数字,用 vue 的端口 的隧道:

cloudflared tunnel create 5173

记下隧道的 UUID 和凭证文件的路径。

步骤 4:创建配置文件

.cloudflared 目录中创建一个 config.yml 文件,内容如下:

url: http://localhost:5173
tunnel: <Tunnel-UUID>
credentials-file: /root/.cloudflared/<Tunnel-UUID>.json

<Tunnel-UUID> 替换为实际的 UUID。

步骤 5:配置 DNS 路由

将流量路由到指定的主机名,例如 vue.example.com

cloudflared tunnel route dns 5173 vue.example.com

步骤 6:运行隧道

运行隧道以代理来自隧道的流量:

cloudflared tunnel run 5173

步骤 7:检查隧道状态

检查隧道是否正常工作:

cloudflared tunnel info 5173

总结

通过以上步骤,您可以成功使用 Cloudflare Tunnel 将本地运行在端口 5173 的应用程序暴露到互联网。您可以通过访问配置的域名(如 vue.example.com)来访问您的本地应用程序。