243 lines
4.1 KiB
Markdown
243 lines
4.1 KiB
Markdown
# DMP Cloudflare Tunnel 部署指南
|
||
|
||
## 🎯 部署目标
|
||
- **域名**: dmp.ink1ing.tech
|
||
- **本地端口**: 3456
|
||
- **Cloudflare 账号**: huinkling@gmail.com
|
||
|
||
---
|
||
|
||
## 📋 快速开始(3步完成)
|
||
|
||
### 第一步:设置 Cloudflare Tunnel
|
||
|
||
在终端中运行:
|
||
|
||
```bash
|
||
cd /Users/inkling/Desktop/dmp
|
||
./setup-tunnel.sh
|
||
```
|
||
|
||
或者双击打开 `setup-tunnel.sh` 文件。
|
||
|
||
这个脚本会自动完成:
|
||
1. ✅ 登录 Cloudflare(如果还未登录)
|
||
2. ✅ 创建名为 `dmp-tunnel` 的隧道
|
||
3. ✅ 配置 DNS 记录 `dmp.ink1ing.tech`
|
||
4. ✅ 验证配置
|
||
|
||
---
|
||
|
||
### 第二步:启动服务
|
||
|
||
**macOS 用户(推荐)**:
|
||
双击运行 `start-tunnel.command`
|
||
|
||
**或在终端运行**:
|
||
```bash
|
||
./start-tunnel.sh
|
||
```
|
||
|
||
---
|
||
|
||
### 第三步:访问应用
|
||
|
||
- **公网访问**: https://dmp.ink1ing.tech
|
||
- **本地访问**: http://localhost:3456
|
||
|
||
---
|
||
|
||
## 🛠 手动设置步骤(如果自动脚本失败)
|
||
|
||
### 1. 登录 Cloudflare
|
||
|
||
```bash
|
||
cloudflared tunnel login
|
||
```
|
||
|
||
浏览器会打开,使用 `huinkling@gmail.com` 登录并授权域名 `ink1ing.tech`。
|
||
|
||
---
|
||
|
||
### 2. 创建 Tunnel
|
||
|
||
```bash
|
||
cloudflared tunnel create dmp-tunnel
|
||
```
|
||
|
||
这会创建一个隧道并生成凭证文件到 `~/.cloudflared/` 目录。
|
||
|
||
---
|
||
|
||
### 3. 配置 DNS
|
||
|
||
```bash
|
||
cloudflared tunnel route dns dmp-tunnel dmp.ink1ing.tech
|
||
```
|
||
|
||
这会在 Cloudflare DNS 中自动添加一条 CNAME 记录,将 `dmp.ink1ing.tech` 指向你的 tunnel。
|
||
|
||
---
|
||
|
||
### 4. 启动服务
|
||
|
||
```bash
|
||
# 启动 Node.js 服务器
|
||
node server.js &
|
||
|
||
# 启动 Cloudflare Tunnel
|
||
cloudflared tunnel --config cloudflare-tunnel.yml run dmp-tunnel
|
||
```
|
||
|
||
---
|
||
|
||
## 📁 文件说明
|
||
|
||
- **cloudflare-tunnel.yml**: Tunnel 配置文件
|
||
- **setup-tunnel.sh**: 一键设置脚本
|
||
- **start-tunnel.sh**: 启动脚本(终端)
|
||
- **start-tunnel.command**: 启动脚本(macOS 双击)
|
||
- **server.js**: DMP 应用主程序
|
||
|
||
---
|
||
|
||
## 🔍 验证和调试
|
||
|
||
### 查看所有 Tunnels
|
||
|
||
```bash
|
||
cloudflared tunnel list
|
||
```
|
||
|
||
### 查看 Tunnel 信息
|
||
|
||
```bash
|
||
cloudflared tunnel info dmp-tunnel
|
||
```
|
||
|
||
### 查看 DNS 路由
|
||
|
||
```bash
|
||
cloudflared tunnel route dns list
|
||
```
|
||
|
||
### 测试本地服务
|
||
|
||
```bash
|
||
curl http://localhost:3456
|
||
```
|
||
|
||
---
|
||
|
||
## 🚫 停止服务
|
||
|
||
在运行 Tunnel 的终端中按 `Ctrl+C`
|
||
|
||
---
|
||
|
||
## 🔧 故障排除
|
||
|
||
### 问题:Tunnel 无法启动
|
||
|
||
**解决方案**:
|
||
```bash
|
||
# 检查凭证文件是否存在
|
||
ls -la ~/.cloudflared/
|
||
|
||
# 重新登录
|
||
cloudflared tunnel login
|
||
|
||
# 删除并重建 tunnel
|
||
cloudflared tunnel delete dmp-tunnel
|
||
cloudflared tunnel create dmp-tunnel
|
||
```
|
||
|
||
---
|
||
|
||
### 问题:DNS 未生效
|
||
|
||
**解决方案**:
|
||
1. 登录 Cloudflare Dashboard
|
||
2. 进入 `ink1ing.tech` 域名设置
|
||
3. 检查 DNS 记录中是否有 `dmp.ink1ing.tech` 的 CNAME 记录
|
||
4. 手动添加或修复:
|
||
```bash
|
||
cloudflared tunnel route dns dmp-tunnel dmp.ink1ing.tech
|
||
```
|
||
|
||
---
|
||
|
||
### 问题:端口被占用
|
||
|
||
**解决方案**:
|
||
```bash
|
||
# 查找占用 3456 端口的进程
|
||
lsof -i :3456
|
||
|
||
# 停止该进程
|
||
kill -9 <PID>
|
||
```
|
||
|
||
---
|
||
|
||
## 🌟 高级配置
|
||
|
||
### 添加多个子域名
|
||
|
||
编辑 `cloudflare-tunnel.yml`:
|
||
|
||
```yaml
|
||
tunnel: dmp-tunnel
|
||
credentials-file: /Users/inkling/.cloudflared/dmp-tunnel.json
|
||
|
||
ingress:
|
||
- hostname: dmp.ink1ing.tech
|
||
service: http://localhost:3456
|
||
- hostname: api.ink1ing.tech
|
||
service: http://localhost:3456
|
||
- service: http_status:404
|
||
```
|
||
|
||
然后添加 DNS 路由:
|
||
```bash
|
||
cloudflared tunnel route dns dmp-tunnel api.ink1ing.tech
|
||
```
|
||
|
||
---
|
||
|
||
### 开机自启动(macOS)
|
||
|
||
创建 LaunchAgent:
|
||
|
||
```bash
|
||
# 安装为系统服务
|
||
sudo cloudflared service install
|
||
```
|
||
|
||
---
|
||
|
||
## 📞 需要帮助?
|
||
|
||
如果遇到问题,检查:
|
||
1. Cloudflare 账号是否正确登录
|
||
2. 域名 `ink1ing.tech` 是否已添加到 Cloudflare
|
||
3. DNS 记录是否正确配置
|
||
4. 本地服务器是否正常运行(访问 http://localhost:3456)
|
||
|
||
---
|
||
|
||
## ✅ 成功标志
|
||
|
||
当你看到以下输出,说明部署成功:
|
||
|
||
```
|
||
✅ DMP 服务已启动 (PID: xxxxx)
|
||
🌐 本地访问: http://localhost:3456
|
||
🔗 正在启动 Cloudflare Tunnel...
|
||
📌 公网访问地址: https://dmp.ink1ing.tech
|
||
|
||
2024-04-01 xx:xx:xx Connection registered connIndex=0 ...
|
||
```
|
||
|
||
现在你可以通过 https://dmp.ink1ing.tech 在任何地方访问你的应用!🎉
|