48 lines
1.5 KiB
Markdown
48 lines
1.5 KiB
Markdown
|
||
|
||
你这样配置,直接运行 `cloudflared tunnel run` 是**不能**成功把 `5173` 转发出去的。
|
||
|
||
虽然你用第一条命令把域名 `221329.cc.cd` 绑定到了你的隧道上,但第二条命令在执行时,**`--url` 参数会被直接忽略掉**。
|
||
|
||
---
|
||
|
||
### 为什么不行?
|
||
|
||
`cloudflared` 的设计逻辑是:
|
||
当你使用 **命名隧道(Named Tunnel,即你创建的 `mac-mini-tunnel`)** 时,它**强制要求**使用本地的 `config.yml` 配置文件来管理转发规则(Ingress Rules),或者通过 Cloudflare 网页后台(Zero Trust Dashboard)来配置。
|
||
|
||
你在命令行里强行拼凑的 `--url http://localhost:5173` 只有在运行临时隧道(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:5173
|
||
- 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:5173 mac-mini-tunnel
|