Files
website-enchun-mgr/docs/coolify-cloudflare-deployment-guide.md
pkupuk f6b806617e docs: add research assets, screenshots and guides
Include supplementary documentation, research notes on Lexical/UX, and setup guides.
2026-02-11 11:51:35 +08:00

115 lines
2.5 KiB
Markdown
Raw 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.

# Coolify + Cloudflare Tunnel 部署指南
## 問題摘要
原本透過 Coolify 的 Traefik 反向代理部署 Docker 容器,遇到 503/404 錯誤。
### 根本原因
1. **Coolify beta 版本 (4.0.0-beta.442)** 的 Traefik 無法正確路由 Docker 容器
2. **Cloudflare Tunnel 萬用字元規則** (`*.anlstudio.cc`) 優先於特定主機名稱規則
### 解決方案
繞過 Traefik改用 Cloudflare Tunnel 直接連線到容器。
---
## 部署新映像檔 (Docker Image) 步驟
### 1. 建立 Coolify 應用程式
```bash
coolify app create dockerimage \
--server-uuid <伺服器UUID> \
--project-uuid <專案UUID> \
--docker-registry-image-name "your-image:tag" \
--ports-exposes "3000" \
--domains "http://your-domain.anlstudio.cc"
```
### 2. 同步環境變數
```bash
coolify app env sync <app-uuid> --file .env.your-app
```
### 3. 取得容器 IP
```bash
# SSH 進入伺服器
ssh -i ~/Desktop/ssh-key.key ubuntu@138.2.104.7
# 查詢容器 IP
docker inspect $(docker ps -qf 'label=coolify.name=<app-uuid>') \
--format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
```
### 4. 設定 Cloudflare Tunnel
**Cloudflare Zero Trust Dashboard****Networks****Tunnels** 新增 Public Hostname
| 欄位 | 值 |
|-----|---|
| Subdomain | `your-subdomain` |
| Domain | `anlstudio.cc` |
| Type | `HTTP` (非 HTTPS!) |
| URL | `<容器IP>:3000` |
### 5. ⚠️ 重要:調整路由順序
**特定主機名稱必須排在萬用字元之前!**
正確順序:
```
1. your-domain.anlstudio.cc → http://<容器IP>:3000
2. *.anlstudio.cc → http://138.2.104.7:80
```
### 6. 重啟 Cloudflared
```bash
docker restart cloudflared-pw00w88ss4ckkg8kwcgw0kws
```
---
## 部署注意事項
> [!WARNING]
> **容器 IP 會在每次重啟/重新部署後變更!**
每次重新部署後需要:
1. 重新查詢容器 IP
2. 更新 Cloudflare Tunnel 的 URL
### 長期解決方案
- 升級 Coolify 到正式版本,讓 Traefik 正常運作
- 或將 cloudflared 加入容器網路,使用容器名稱而非 IP
---
## 快速驗證指令
```bash
# 測試連線
curl -sS -o /dev/null -w "%{http_code}" https://your-domain.anlstudio.cc/
# 查看容器狀態
coolify app get <app-uuid> --format pretty
# 查看容器日誌
coolify app logs <app-uuid> --lines 30
```
---
## 相關 UUID 參考
| 項目 | UUID |
|-----|-----|
| 伺服器 | `igcskocw4kcgko4wswc8wwoo` |
| PayloadCMS 專案 | `j8kkko4gc0gs00w44gs8swk0` |
| Enchuna CMS v2 應用程式 | `q0kcgo0gs8w4c08wowowg4ss` |