feat: 新增 OCRmyPDF 轉換引擎 (v0.1.14)
## 新功能 - OCRmyPDF 轉換引擎:將掃描版 PDF 轉換為可搜尋 PDF - 支援 7 種語言:en, zh-TW, zh, ja, ko, de, fr - 與 PDFMathTranslate 風格一致的 UI 格式 (pdf-<lang>) - 自動偵測頁面方向並旋轉 - 自動校正傾斜 - 跳過已有文字層的頁面 - 詳細的 5 階段處理進度輸出 ## 建置 - Dockerfile:安裝 ocrmypdf 與 Tesseract OCR 語言包 ## 文件 - 更新 OCR 功能文件 - 文件目錄結構改為中文名稱 ## 測試 - 修復 BabelDOC 和 PDFMathTranslate 測試的 OCR mock - 所有 345 個測試通過
This commit is contained in:
parent
f24eec070c
commit
a06df23b1d
53 changed files with 1427 additions and 675 deletions
273
docs/部署指南/Docker.md
Normal file
273
docs/部署指南/Docker.md
Normal file
|
|
@ -0,0 +1,273 @@
|
|||
# Docker 部署指南
|
||||
|
||||
本文件說明如何使用 Docker 部署 ConvertX-CN。
|
||||
|
||||
---
|
||||
|
||||
## Docker Image 版本
|
||||
|
||||
### 官方預建版(推薦)
|
||||
|
||||
| Tag | 說明 |
|
||||
| ----------------------------- | ---------- |
|
||||
| `convertx/convertx-cn:latest` | 最新穩定版 |
|
||||
| `convertx/convertx-cn:v0.1.x` | 指定版本號 |
|
||||
|
||||
**內建功能:**
|
||||
|
||||
- ✅ 核心轉換工具(FFmpeg、LibreOffice、ImageMagick 等)
|
||||
- ✅ OCR 支援:英文、繁/簡中文、日文、韓文、德文、法文
|
||||
- ✅ 字型:Noto CJK、Liberation、自訂中文字型
|
||||
- ✅ TexLive(支援 CJK/德/法)
|
||||
|
||||
**Image 大小:約 4-6 GB**
|
||||
|
||||
### 完整版(自行 Build)
|
||||
|
||||
使用 `Dockerfile.full` 自行建構,適合需要:
|
||||
|
||||
- 65 種 OCR 語言
|
||||
- 完整 TexLive
|
||||
- 額外字型套件
|
||||
|
||||
```bash
|
||||
docker build -f Dockerfile.full -t convertx-cn-full .
|
||||
```
|
||||
|
||||
> ⚠️ 注意:Image 大小可能超過 **10GB**,Build 時間約 **30-60 分鐘**
|
||||
|
||||
---
|
||||
|
||||
## Docker Run
|
||||
|
||||
### 基本啟動
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name convertx-cn \
|
||||
--restart unless-stopped \
|
||||
-p 3000:3000 \
|
||||
-v ./data:/app/data \
|
||||
-e TZ=Asia/Taipei \
|
||||
-e JWT_SECRET=你的隨機字串至少32字元 \
|
||||
convertx/convertx-cn:latest
|
||||
```
|
||||
|
||||
### 參數說明
|
||||
|
||||
| 參數 | 說明 |
|
||||
| -------------------------- | ---------- |
|
||||
| `-d` | 背景執行 |
|
||||
| `--name convertx-cn` | 容器名稱 |
|
||||
| `--restart unless-stopped` | 自動重啟 |
|
||||
| `-p 3000:3000` | 連接埠映射 |
|
||||
| `-v ./data:/app/data` | 資料持久化 |
|
||||
| `-e TZ=Asia/Taipei` | 時區設定 |
|
||||
|
||||
### 進階選項
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name convertx-cn \
|
||||
--restart unless-stopped \
|
||||
-p 3000:3000 \
|
||||
-v ./data:/app/data \
|
||||
-e TZ=Asia/Taipei \
|
||||
-e JWT_SECRET=你的隨機字串 \
|
||||
-e ACCOUNT_REGISTRATION=false \
|
||||
-e HTTP_ALLOWED=true \
|
||||
-e AUTO_DELETE_EVERY_N_HOURS=24 \
|
||||
convertx/convertx-cn:latest
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 資料持久化
|
||||
|
||||
### Volume 結構
|
||||
|
||||
```
|
||||
./data/
|
||||
├── convertx.db # SQLite 資料庫
|
||||
├── uploads/ # 上傳的原始檔案
|
||||
└── output/ # 轉換後的檔案
|
||||
```
|
||||
|
||||
### 建立資料夾
|
||||
|
||||
**重要**:請務必先建立資料夾,否則 Docker 會建立匿名 volume。
|
||||
|
||||
**Linux / macOS:**
|
||||
|
||||
```bash
|
||||
mkdir -p ~/convertx-cn/data
|
||||
```
|
||||
|
||||
**Windows PowerShell:**
|
||||
|
||||
```powershell
|
||||
mkdir C:\convertx-cn\data
|
||||
```
|
||||
|
||||
### 備份與還原
|
||||
|
||||
**備份:**
|
||||
|
||||
```bash
|
||||
tar -czvf convertx-backup-$(date +%Y%m%d).tar.gz ./data
|
||||
```
|
||||
|
||||
**還原:**
|
||||
|
||||
```bash
|
||||
tar -xzvf convertx-backup-20260120.tar.gz
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 硬體加速
|
||||
|
||||
### NVIDIA GPU (CUDA/NVENC)
|
||||
|
||||
1. 安裝 [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html)
|
||||
|
||||
2. Docker Compose 配置:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
convertx:
|
||||
image: convertx/convertx-cn:latest
|
||||
deploy:
|
||||
resources:
|
||||
reservations:
|
||||
devices:
|
||||
- driver: nvidia
|
||||
count: all
|
||||
capabilities: [gpu]
|
||||
environment:
|
||||
- FFMPEG_ARGS=-hwaccel cuda -hwaccel_output_format cuda
|
||||
- FFMPEG_OUTPUT_ARGS=-c:v h264_nvenc -preset fast
|
||||
```
|
||||
|
||||
### Intel Quick Sync Video (QSV)
|
||||
|
||||
```yaml
|
||||
services:
|
||||
convertx:
|
||||
image: convertx/convertx-cn:latest
|
||||
devices:
|
||||
- /dev/dri:/dev/dri
|
||||
environment:
|
||||
- FFMPEG_ARGS=-hwaccel qsv
|
||||
- FFMPEG_OUTPUT_ARGS=-c:v h264_qsv -preset faster
|
||||
```
|
||||
|
||||
### AMD VAAPI
|
||||
|
||||
```yaml
|
||||
services:
|
||||
convertx:
|
||||
image: convertx/convertx-cn:latest
|
||||
devices:
|
||||
- /dev/dri:/dev/dri
|
||||
environment:
|
||||
- FFMPEG_ARGS=-hwaccel vaapi -hwaccel_device /dev/dri/renderD128
|
||||
- FFMPEG_OUTPUT_ARGS=-c:v h264_vaapi
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 資源限制
|
||||
|
||||
### 記憶體限制
|
||||
|
||||
```yaml
|
||||
services:
|
||||
convertx:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 4G
|
||||
reservations:
|
||||
memory: 2G
|
||||
```
|
||||
|
||||
### CPU 限制
|
||||
|
||||
```yaml
|
||||
services:
|
||||
convertx:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "2"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 版本更新
|
||||
|
||||
**1. 拉取最新版本:**
|
||||
|
||||
```bash
|
||||
docker pull convertx/convertx-cn:latest
|
||||
```
|
||||
|
||||
**2. 停止並移除舊容器:**
|
||||
|
||||
```bash
|
||||
docker stop convertx-cn
|
||||
docker rm convertx-cn
|
||||
```
|
||||
|
||||
**3. 重新啟動(使用相同的參數):**
|
||||
|
||||
```bash
|
||||
docker run -d --name convertx-cn ...
|
||||
```
|
||||
|
||||
或使用 Docker Compose:
|
||||
|
||||
```bash
|
||||
docker compose pull
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 疑難排解
|
||||
|
||||
### 查看日誌
|
||||
|
||||
```bash
|
||||
docker logs convertx-cn
|
||||
```
|
||||
|
||||
持續追蹤日誌:
|
||||
|
||||
```bash
|
||||
docker logs -f convertx-cn
|
||||
```
|
||||
|
||||
### 進入容器
|
||||
|
||||
```bash
|
||||
docker exec -it convertx-cn /bin/bash
|
||||
```
|
||||
|
||||
### 常見問題
|
||||
|
||||
| 問題 | 解決方法 |
|
||||
| ----------- | ------------------------------ |
|
||||
| 啟動失敗 | 檢查日誌 `docker logs` |
|
||||
| Port 被占用 | 改用其他 port `-p 8080:3000` |
|
||||
| 權限錯誤 | `chmod -R 777 ./data` |
|
||||
| 記憶體不足 | 增加記憶體限制或減少同時轉換數 |
|
||||
|
||||
---
|
||||
|
||||
## 相關文件
|
||||
|
||||
- [Docker Compose 詳解](docker-compose.md)
|
||||
- [反向代理設定](反向代理.md)
|
||||
- [環境變數設定](../配置設定/環境變數.md)
|
||||
163
docs/部署指南/docker-compose.md
Normal file
163
docs/部署指南/docker-compose.md
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
# Docker Compose 詳解
|
||||
|
||||
本文件說明 docker-compose.yml 的完整設定選項。
|
||||
|
||||
---
|
||||
|
||||
## 基本結構
|
||||
|
||||
```yaml
|
||||
services:
|
||||
convertx:
|
||||
image: convertx/convertx-cn:latest
|
||||
container_name: convertx-cn
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
environment:
|
||||
- TZ=Asia/Taipei
|
||||
- JWT_SECRET=your-secret-key
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 映像檔選擇
|
||||
|
||||
```yaml
|
||||
image: convertx/convertx-cn:latest # 最新穩定版
|
||||
image: convertx/convertx-cn:v0.1.9 # 指定版本
|
||||
```
|
||||
|
||||
- `latest`:自動獲取最新版本,適合測試環境
|
||||
- 指定版本:適合生產環境,避免意外升級
|
||||
|
||||
詳見 [版本選擇指南](../versions/)。
|
||||
|
||||
---
|
||||
|
||||
## 連接埠設定
|
||||
|
||||
```yaml
|
||||
ports:
|
||||
- "3000:3000" # 主機埠:容器埠
|
||||
- "8080:3000" # 使用 8080 埠
|
||||
- "127.0.0.1:3000:3000" # 僅本地存取
|
||||
```
|
||||
|
||||
| 設定 | 說明 |
|
||||
| ----------------------- | -------------------- |
|
||||
| `"3000:3000"` | 所有網路介面可存取 |
|
||||
| `"127.0.0.1:3000:3000"` | 僅本機可存取 |
|
||||
| `"8080:3000"` | 使用 8080 埠對外開放 |
|
||||
|
||||
---
|
||||
|
||||
## 資料儲存
|
||||
|
||||
### 使用資料夾掛載(推薦)
|
||||
|
||||
```yaml
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
```
|
||||
|
||||
- 資料存在主機上的 `./data` 資料夾
|
||||
- 方便備份、遷移、直接存取
|
||||
|
||||
### 使用 Docker Volume
|
||||
|
||||
```yaml
|
||||
volumes:
|
||||
- convertx_data:/app/data
|
||||
|
||||
volumes:
|
||||
convertx_data:
|
||||
```
|
||||
|
||||
- 資料由 Docker 管理
|
||||
- 備份需透過 Docker 指令
|
||||
|
||||
---
|
||||
|
||||
## 環境變數
|
||||
|
||||
### 必要設定
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- JWT_SECRET=your-secret-key-at-least-32-chars
|
||||
```
|
||||
|
||||
### 建議設定
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- TZ=Asia/Taipei
|
||||
- HTTP_ALLOWED=true # 本地測試
|
||||
- ACCOUNT_REGISTRATION=true
|
||||
```
|
||||
|
||||
### 生產環境設定
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- TZ=Asia/Taipei
|
||||
- JWT_SECRET=your-production-secret
|
||||
- HTTP_ALLOWED=false
|
||||
- TRUST_PROXY=true
|
||||
- ACCOUNT_REGISTRATION=false
|
||||
- AUTO_DELETE_EVERY_N_HOURS=24
|
||||
```
|
||||
|
||||
完整環境變數說明請參考 [環境變數文件](../配置設定/環境變數.md)。
|
||||
|
||||
---
|
||||
|
||||
## 重啟策略
|
||||
|
||||
```yaml
|
||||
restart: unless-stopped # 推薦
|
||||
restart: always # 總是重啟
|
||||
restart: on-failure # 僅失敗時重啟
|
||||
restart: "no" # 不自動重啟
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 資源限制
|
||||
|
||||
```yaml
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 4G
|
||||
cpus: "2"
|
||||
reservations:
|
||||
memory: 1G
|
||||
cpus: "0.5"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 健康檢查
|
||||
|
||||
```yaml
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3000/healthcheck"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 完整範例
|
||||
|
||||
請參考 [Docker Compose 範例資料夾](../docker-compose/):
|
||||
|
||||
- `compose.minimal.yml` - 最精簡設定
|
||||
- `compose.production.yml` - 生產環境
|
||||
- `compose.reference.yml` - 完整參考
|
||||
132
docs/部署指南/quickstart.md
Normal file
132
docs/部署指南/quickstart.md
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
# 快速部署指南
|
||||
|
||||
本文件提供 ConvertX-CN 的完整部署步驟,適合第一次使用 Docker 的使用者。
|
||||
|
||||
---
|
||||
|
||||
## 前置需求
|
||||
|
||||
- [Docker](https://www.docker.com/products/docker-desktop/) 或 [Docker Engine](https://docs.docker.com/engine/install/)
|
||||
- 約 6 GB 硬碟空間
|
||||
- 網路連線(首次下載映像檔)
|
||||
|
||||
---
|
||||
|
||||
## 步驟 1:安裝 Docker
|
||||
|
||||
### Windows / macOS
|
||||
|
||||
下載並安裝 [Docker Desktop](https://www.docker.com/products/docker-desktop/)。
|
||||
|
||||
### Linux
|
||||
|
||||
```bash
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
sudo usermod -aG docker $USER
|
||||
# 登出再登入,讓群組生效
|
||||
```
|
||||
|
||||
驗證安裝:
|
||||
|
||||
```bash
|
||||
docker --version
|
||||
docker compose version
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 步驟 2:建立專案資料夾
|
||||
|
||||
### Linux / macOS
|
||||
|
||||
```bash
|
||||
mkdir -p ~/convertx-cn/data
|
||||
cd ~/convertx-cn
|
||||
```
|
||||
|
||||
### Windows (PowerShell)
|
||||
|
||||
```powershell
|
||||
mkdir C:\convertx-cn\data
|
||||
cd C:\convertx-cn
|
||||
```
|
||||
|
||||
> ⚠️ `data` 資料夾必須先建立,否則 Docker 會建立匿名 volume,導致資料難以存取。
|
||||
|
||||
---
|
||||
|
||||
## 步驟 3:建立 docker-compose.yml
|
||||
|
||||
在專案資料夾建立 `docker-compose.yml`:
|
||||
|
||||
> 💡 `JWT_SECRET` 請改成你自己的隨機字串(至少 32 字元)
|
||||
|
||||
```yaml
|
||||
services:
|
||||
convertx:
|
||||
image: convertx/convertx-cn:latest
|
||||
container_name: convertx-cn
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
environment:
|
||||
- TZ=Asia/Taipei
|
||||
- JWT_SECRET=your-random-secret-at-least-32-chars
|
||||
```
|
||||
|
||||
### 必要參數說明
|
||||
|
||||
| 參數 | 說明 |
|
||||
| ------------ | ---------------------------------- |
|
||||
| `./data` | 存放上傳檔案與轉換結果,必須先建立 |
|
||||
| `JWT_SECRET` | 登入驗證金鑰,不設會每次重啟被登出 |
|
||||
|
||||
---
|
||||
|
||||
## 步驟 4:啟動服務
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
首次執行會下載映像檔(約 4-6 GB),需等待幾分鐘。
|
||||
|
||||
查看狀態:
|
||||
|
||||
```bash
|
||||
docker compose ps
|
||||
docker compose logs -f # Ctrl+C 退出
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 步驟 5:使用
|
||||
|
||||
1. 開啟瀏覽器,訪問 `http://localhost:3000`
|
||||
2. 點擊 **Register** 註冊帳號
|
||||
3. 開始轉換檔案
|
||||
|
||||
首次註冊的帳號會自動成為管理員。
|
||||
|
||||
---
|
||||
|
||||
## 常見問題
|
||||
|
||||
| 問題 | 解法 |
|
||||
| -------------------- | ------------------------------------ |
|
||||
| 登入後又被踢回登入頁 | 加上 `HTTP_ALLOWED=true` |
|
||||
| 重啟後資料消失 | 確認 `./data:/app/data` 且資料夾存在 |
|
||||
| 重啟後被登出 | 設定固定的 `JWT_SECRET` |
|
||||
| 3000 埠被佔用 | 改用 `"8080:3000"` |
|
||||
|
||||
更多問題請參考 [FAQ](../快速入門/常見問題.md)。
|
||||
|
||||
---
|
||||
|
||||
## 下一步
|
||||
|
||||
- [環境變數完整說明](../配置設定/環境變數.md)
|
||||
- [反向代理與 HTTPS](反向代理.md)
|
||||
- [版本更新方法](update.md)
|
||||
146
docs/部署指南/update.md
Normal file
146
docs/部署指南/update.md
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
# 版本更新指南
|
||||
|
||||
本文件說明如何更新 ConvertX-CN 到新版本。
|
||||
|
||||
---
|
||||
|
||||
## 使用 Docker Compose 更新
|
||||
|
||||
### 更新到最新版
|
||||
|
||||
```bash
|
||||
# 1. 進入專案資料夾
|
||||
cd ~/convertx-cn
|
||||
|
||||
# 2. 停止服務
|
||||
docker compose down
|
||||
|
||||
# 3. 拉取最新映像檔
|
||||
docker compose pull
|
||||
|
||||
# 4. 重新啟動
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### 更新到指定版本
|
||||
|
||||
修改 `docker-compose.yml`(指定要更新的版本號):
|
||||
|
||||
```yaml
|
||||
services:
|
||||
convertx:
|
||||
image: convertx/convertx-cn:v0.1.9
|
||||
```
|
||||
|
||||
然後執行:
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
docker compose pull
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 驗證更新
|
||||
|
||||
### 查看 Log
|
||||
|
||||
```bash
|
||||
docker compose logs | head -20
|
||||
```
|
||||
|
||||
### 檢查網頁版本
|
||||
|
||||
開啟 `http://localhost:3000`,頁面底部會顯示版本號。
|
||||
|
||||
### 檢查映像檔版本
|
||||
|
||||
```bash
|
||||
docker images convertx/convertx-cn
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 備份建議
|
||||
|
||||
更新前建議備份 `data` 資料夾:
|
||||
|
||||
```bash
|
||||
# Linux / macOS
|
||||
cp -r ./data ./data.backup.$(date +%Y%m%d)
|
||||
|
||||
# Windows PowerShell
|
||||
Copy-Item -Recurse .\data .\data.backup.$(Get-Date -Format "yyyyMMdd")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 回滾版本
|
||||
|
||||
如果新版本有問題,可以回滾到舊版本(將版本號改為舊版本):
|
||||
|
||||
```yaml
|
||||
services:
|
||||
convertx:
|
||||
image: convertx/convertx-cn:v0.1.8
|
||||
```
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
docker compose pull
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 清理舊映像檔
|
||||
|
||||
更新後可清理不再使用的舊映像檔,釋放磁碟空間:
|
||||
|
||||
```bash
|
||||
docker image prune -a
|
||||
```
|
||||
|
||||
> ⚠️ 此指令會刪除所有未使用的映像檔,不只是 ConvertX-CN。
|
||||
|
||||
只刪除 ConvertX-CN 舊版本:
|
||||
|
||||
```bash
|
||||
# 列出所有版本
|
||||
docker images convertx/convertx-cn
|
||||
|
||||
# 刪除特定版本
|
||||
docker rmi convertx/convertx-cn:v0.1.7
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 自動更新(進階)
|
||||
|
||||
可使用 [Watchtower](https://containrrr.dev/watchtower/) 自動更新容器:
|
||||
|
||||
> 💡 `--interval 86400` — 每 24 小時檢查一次更新
|
||||
|
||||
```yaml
|
||||
services:
|
||||
convertx:
|
||||
image: convertx/convertx-cn:latest
|
||||
# ... 其他設定
|
||||
|
||||
watchtower:
|
||||
image: containrrr/watchtower
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
command: --interval 86400
|
||||
```
|
||||
|
||||
> ⚠️ 自動更新適合測試環境。生產環境建議手動更新,確認新版本穩定後再升級。
|
||||
|
||||
---
|
||||
|
||||
## 相關文件
|
||||
|
||||
- [版本選擇指南](../versions/)
|
||||
- [GitHub Releases](https://github.com/pi-docket/ConvertX-CN/releases)
|
||||
- [Changelog](../../CHANGELOG.md)
|
||||
290
docs/部署指南/反向代理.md
Normal file
290
docs/部署指南/反向代理.md
Normal file
|
|
@ -0,0 +1,290 @@
|
|||
# 反向代理設定
|
||||
|
||||
本文件說明如何在 Nginx、Traefik、Caddy 等反向代理後部署 ConvertX-CN。
|
||||
|
||||
---
|
||||
|
||||
## 必要環境變數
|
||||
|
||||
透過反向代理存取時,請設定:
|
||||
|
||||
- `TRUST_PROXY=true` — 信任 X-Forwarded-\* headers
|
||||
- `HTTP_ALLOWED=false` — Proxy 已處理 HTTPS
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- TRUST_PROXY=true
|
||||
- HTTP_ALLOWED=false
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Nginx
|
||||
|
||||
### 基本配置
|
||||
|
||||
```nginx
|
||||
# /etc/nginx/sites-available/convertx
|
||||
server {
|
||||
listen 80;
|
||||
server_name convertx.example.com;
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name convertx.example.com;
|
||||
|
||||
# SSL 憑證(Let's Encrypt)
|
||||
ssl_certificate /etc/letsencrypt/live/convertx.example.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/convertx.example.com/privkey.pem;
|
||||
|
||||
# SSL 安全設定
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
|
||||
|
||||
# 檔案上傳大小限制
|
||||
client_max_body_size 500M;
|
||||
|
||||
# 超時設定(大檔案轉換需要)
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
# 必要的 headers
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# WebSocket 支援
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 啟用設定
|
||||
|
||||
```bash
|
||||
sudo ln -s /etc/nginx/sites-available/convertx /etc/nginx/sites-enabled/
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Traefik
|
||||
|
||||
### Docker Labels 方式
|
||||
|
||||
```yaml
|
||||
# docker-compose.yml
|
||||
services:
|
||||
convertx:
|
||||
image: convertx/convertx-cn:latest
|
||||
container_name: convertx-cn
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
environment:
|
||||
- JWT_SECRET=${JWT_SECRET}
|
||||
- TRUST_PROXY=true
|
||||
- HTTP_ALLOWED=false
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.convertx.rule=Host(`convertx.example.com`)"
|
||||
- "traefik.http.routers.convertx.entrypoints=websecure"
|
||||
- "traefik.http.routers.convertx.tls=true"
|
||||
- "traefik.http.routers.convertx.tls.certresolver=letsencrypt"
|
||||
- "traefik.http.services.convertx.loadbalancer.server.port=3000"
|
||||
networks:
|
||||
- traefik-network
|
||||
|
||||
networks:
|
||||
traefik-network:
|
||||
external: true
|
||||
```
|
||||
|
||||
### 動態配置檔
|
||||
|
||||
```yaml
|
||||
# traefik/dynamic/convertx.yml
|
||||
http:
|
||||
routers:
|
||||
convertx:
|
||||
rule: "Host(`convertx.example.com`)"
|
||||
service: convertx
|
||||
entryPoints:
|
||||
- websecure
|
||||
tls:
|
||||
certResolver: letsencrypt
|
||||
|
||||
services:
|
||||
convertx:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- url: "http://127.0.0.1:3000"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Caddy
|
||||
|
||||
### 基本配置
|
||||
|
||||
```
|
||||
convertx.example.com {
|
||||
reverse_proxy localhost:3000 {
|
||||
header_up X-Real-IP {remote_host}
|
||||
header_up X-Forwarded-Proto {scheme}
|
||||
}
|
||||
|
||||
request_body {
|
||||
max_size 500MB
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 子路徑部署
|
||||
|
||||
```
|
||||
example.com {
|
||||
handle_path /convertx/* {
|
||||
reverse_proxy localhost:3000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
記得設定環境變數:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- WEBROOT=/convertx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Cloudflare Tunnel
|
||||
|
||||
### 1. 建立 Tunnel
|
||||
|
||||
```bash
|
||||
cloudflared tunnel create convertx
|
||||
```
|
||||
|
||||
### 2. 配置
|
||||
|
||||
```yaml
|
||||
# ~/.cloudflared/config.yml
|
||||
tunnel: <tunnel-id>
|
||||
credentials-file: ~/.cloudflared/<tunnel-id>.json
|
||||
|
||||
ingress:
|
||||
- hostname: convertx.example.com
|
||||
service: http://localhost:3000
|
||||
- service: http_status:404
|
||||
```
|
||||
|
||||
### 3. 啟動
|
||||
|
||||
```bash
|
||||
cloudflared tunnel run convertx
|
||||
```
|
||||
|
||||
### 4. 環境變數
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- TRUST_PROXY=true
|
||||
- HTTP_ALLOWED=false
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 子路徑部署
|
||||
|
||||
如需在子路徑部署(如 `https://example.com/convertx`):
|
||||
|
||||
### 1. 設定環境變數
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- WEBROOT=/convertx
|
||||
```
|
||||
|
||||
### 2. Nginx 配置
|
||||
|
||||
```nginx
|
||||
location /convertx/ {
|
||||
proxy_pass http://localhost:3000/;
|
||||
# ... 其他 proxy 設定
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Caddy 配置
|
||||
|
||||
```
|
||||
example.com {
|
||||
handle_path /convertx/* {
|
||||
reverse_proxy localhost:3000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## HTTPS 憑證
|
||||
|
||||
### Let's Encrypt(推薦)
|
||||
|
||||
使用 Certbot 自動取得憑證:
|
||||
|
||||
```bash
|
||||
sudo apt install certbot python3-certbot-nginx
|
||||
sudo certbot --nginx -d convertx.example.com
|
||||
```
|
||||
|
||||
### 自簽憑證(測試用)
|
||||
|
||||
```bash
|
||||
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
|
||||
-keyout /etc/nginx/ssl/convertx.key \
|
||||
-out /etc/nginx/ssl/convertx.crt
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 疑難排解
|
||||
|
||||
### 登入後被踢回登入頁
|
||||
|
||||
1. 確認 `TRUST_PROXY=true`
|
||||
2. 確認反向代理正確傳送 `X-Forwarded-Proto` header
|
||||
|
||||
### 上傳檔案失敗
|
||||
|
||||
1. 調高 `client_max_body_size`(Nginx)
|
||||
2. 調高 `request_body max_size`(Caddy)
|
||||
3. 調高超時設定
|
||||
|
||||
### WebSocket 連線失敗
|
||||
|
||||
確認反向代理正確處理 WebSocket:
|
||||
|
||||
```nginx
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 相關文件
|
||||
|
||||
- [Docker 部署](docker.md)
|
||||
- [安全性設定](../configuration/security.md)
|
||||
- [環境變數](../configuration/environment-variables.md)
|
||||
Loading…
Add table
Add a link
Reference in a new issue