Cloudflare 提供的 cloudflared 工具,作为其边缘计算平台的一部分,可让开发者直接从终端或脚本调用 Cloudflare 服务。该工具借助 TCP 或 HTTP 连接与 Cloudflare 网络通信,为开发工作带来便利。
若要在项目中使用 cloudflared,请按以下步骤操作:
go get -v github.com/cloudflare/cloudflared/cmd/cloudflared@latest
cloudflared tunnel --url http://localhost:8080
cloudflared.toml 文件,并添加以下内容:[tunnel]
name = "my-tunnel"
然后运行命令:cloudflared tunnel --config cloudflared.toml
# 创建一个新的隧道并绑定到项目中
cloudflared tunnel create project=frontend
# 结果将返回隧道 ID 和配置文件路径
# 根据项目名称删除特定隧道
cloudflared tunnel delete id= project=frontend
暂未提供高级用法示例,后续可根据实际需求补充。
以下是 cloudflared 常用的一些配置参数:
| 参数类型 | 参数 | 详情 |
|---|---|---|
| 基本参数 | -h, --help |
显示帮助信息 |
| 基本参数 | -v, --version |
显示版本号 |
| 基本参数 | --config |
指定配置文件路径 |
| 隧道相关参数 | --url |
配置要代理的目标 URL |
| 隧道相关参数 | --tunnel-id |
指定要操作的隧道 ID |
| 隧道相关参数 | --project |
指定项目名称,用于区分不同的隧道 |
运行以下命令可以查看所有已创建的隧道:
cloudflared tunnel list
结果将显示所有隧道及其对应的 ID。
默认情况下,cloudflared 会在当前工作目录中查找 cloudflared.toml 文件。如果需要指定其他位置,可以使用 --config 参数。
文档中未提及许可证相关信息。