Files
hfb_sys/docs/cf临时穿透.md
2026-07-25 16:31:42 +08:00

48 lines
1.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
你这样配置,直接运行 `cloudflared tunnel run` 是**不能**成功把 `5189` 转发出去的。
虽然你用第一条命令把域名 `221329.cc.cd` 绑定到了你的隧道上,但第二条命令在执行时,**`--url` 参数会被直接忽略掉**。
---
### 为什么不行?
`cloudflared` 的设计逻辑是:
当你使用 **命名隧道(Named Tunnel,即你创建的 `mac-mini-tunnel`** 时,它**强制要求**使用本地的 `config.yml` 配置文件来管理转发规则(Ingress Rules),或者通过 Cloudflare 网页后台(Zero Trust Dashboard)来配置。
你在命令行里强行拼凑的 `--url http://localhost:5189` 只有在运行临时隧道(Quick Tunnels,不指定隧道名的那种)时才会生效。
---
#### 做法 B:正规搞法,用你的固定域名(使用本地配置文件)
如果你非要用 `221329.cc.cd` 这个域名,你需要两步:
**第一步**:在你的 `~/.cloudflared/` 目录下(或者当前执行目录下)新建一个 `config.yml` 文件,里面写入转发规则:
```yaml
tunnel: mac-mini-tunnel
credentials-file: /Users/你的用户名/.cloudflared/你的隧道ID.json
ingress:
- hostname: 221329.cc.cd
service: http://localhost:5189
- service: http_status:404
```
**第二步**:启动隧道时**不要**加 `--url`,直接让它读配置运行:
```bash
cloudflared tunnel run mac-mini-tunnel
```
cloudflared tunnel route dns mac-mini-tunnel 221329.cc.cd
cloudflared tunnel run --url http://localhost:5189 mac-mini-tunnel