切換菜單
切換偏好設定選單
切換個人選單
尚未登入
若您做出任何編輯,會公開您的 IP 位址。
於 2026年5月9日 (六) 03:46 由 Lusky0對話 | 貢獻 所做的修訂 (创建页面,内容为“# CLIProxyAPI Docker 部署教程 > 环境:Debian 13 | Docker Compose | Nginx 反向代理 > 访问域名:`xxx.com` ------ ## 一、安装系统依赖 ```bash apt update && apt upgrade -y apt install -y git nginx curl # 安装 Docker bash <(curl -fsSL https://get.docker.com) systemctl enable --now docker ``` ------ ## 二、部署 CLIProxyAPI ### 2.1 克隆项目 ```bash git clone https://github.com/router-for-me/CLIProxyAPI.git cd CLIProxyAPI cp c…”)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
  1. CLIProxyAPI Docker 部署教程

> 環境:Debian 13 | Docker Compose | Nginx 反向代理 > 訪問域名:`xxx.com`


    1. 一、安裝系統依賴

```bash apt update && apt upgrade -y apt install -y git nginx curl

  1. 安裝 Docker

bash <(curl -fsSL https://get.docker.com) systemctl enable --now docker ```


    1. 二、部署 CLIProxyAPI
      1. 2.1 克隆項目

```bash git clone https://github.com/router-for-me/CLIProxyAPI.git cd CLIProxyAPI cp config.example.yaml config.yaml ```

      1. 2.2 編輯配置文件

```bash nano config.yaml ```

寫入以下配置:

```yaml port: 8317

auth-dir: "~/.cli-proxy-api"

request-retry: 3

quota-exceeded:

 switch-project: true
 switch-preview-model: true

api-keys:

 - "your-api-key"        # 客户端访问时使用的 Key,先随便填一个,后续可在面板修改

remote-management:

 allow-remote: true
 secret-key: "your-management-password"    # 管理面板登录密码

```

> `api-keys` 不能留空,先填一個佔位,進管理面板後再改。 > `secret-key` 首次啟動後會自動 bcrypt 加密寫回配置,用明文登錄即可。

      1. 2.3 修改 docker-compose.yml

將 8317 和 8085 綁定到本地,OAuth 回調端口保持公網可達:

```bash nano docker-compose.yml ```

找到 `ports` 部分,修改為:

```yaml ports:

 - "127.0.0.1:8317:8317"    # 主 API,走 Nginx 反代
 - "127.0.0.1:8085:8085"    # 内部端口(实际未使用)
 - "1455:1455"               # OAuth 回调(Claude/Codex)
 - "54545:54545"             # OAuth 回调(Gemini CLI)
 - "51121:51121"             # OAuth 回调(Antigravity)
 - "11451:11451"             # OAuth 回调(其他)

```

      1. 2.4 啟動服務

```bash bash docker-build.sh

  1. 出現選項時輸入 1 回車(使用預構建鏡像,速度快)

```

或直接:

```bash docker compose up -d ```

驗證服務正常運行:

```bash docker compose ps ss -tlnp | grep 8317 # 應看到 127.0.0.1:8317 tail -f ./logs/main.log # 實時日誌 ```


    1. 三、配置防火牆

放行 OAuth 回調端口(API 端口由 Nginx 代理,無需放行):

```bash

  1. ufw

ufw allow 1455/tcp ufw allow 54545/tcp ufw allow 51121/tcp ufw allow 11451/tcp ```


    1. 四、配置 Nginx
      1. 4.1 創建站點配置

先只寫 HTTP 塊,等 certbot 申請完證書後再補 HTTPS:

```bash cat > /etc/nginx/sites-available/xxx.com << 'EOF' server {

   listen 80;
   listen [::]:80;
   server_name xxx.com;
   location / {
       return 301 https://$host$request_uri;
   }

} EOF ```

      1. 4.2 啟用站點

```bash ln -s /etc/nginx/sites-available/xxx.com /etc/nginx/sites-enabled/ nginx -t && systemctl reload nginx ```

      1. 4.3 申請 HTTPS 證書

```bash apt install -y certbot python3-certbot-nginx certbot --nginx -d xxx.com systemctl enable --now certbot.timer ```

      1. 4.4 替換為完整配置

certbot 申請成功後,覆蓋寫入完整的 Nginx 配置:

```bash cat > /etc/nginx/sites-available/xxx.com << 'EOF'

  1. HTTP → 強制跳轉 HTTPS

server {

   listen 80;
   listen [::]:80;
   server_name xxx.com;
   location / {
       return 301 https://$host$request_uri;
   }

}

  1. HTTPS 主配置

server {

   listen 443 ssl;
   listen [::]:443 ssl;
   server_name xxx.com;
   ssl_certificate     /etc/letsencrypt/live/xxx.com/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/xxx.com/privkey.pem;
   include             /etc/letsencrypt/options-ssl-nginx.conf;
   ssl_dhparam         /etc/letsencrypt/ssl-dhparams.pem;
   # 主 API
   location / {
       proxy_pass         http://127.0.0.1:8317;
       proxy_http_version 1.1;
       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;
       # SSE 流式响应必须关闭缓冲
       proxy_buffering    off;
       proxy_cache        off;
       proxy_read_timeout    300s;
       proxy_connect_timeout 75s;
   }

} EOF nginx -t && systemctl reload nginx ```


    1. 五、訪問管理面板

瀏覽器打開:

``` https://xxx.com/management.html ```

- **伺服器地址**:自動填入 `https://xxx.com` - **管理密鑰**:填寫 `config.yaml` 中 `secret-key` 的值


    1. 六、添加 OAuth 認證

在伺服器上執行對應命令生成認證連結:

```bash cd ~/CLIProxyAPI

  1. Claude

docker compose exec cli-proxy-api /CLIProxyAPI/CLIProxyAPI -no-browser --claude-login

  1. Gemini CLI

docker compose exec cli-proxy-api /CLIProxyAPI/CLIProxyAPI -no-browser --login

  1. OpenAI Codex

docker compose exec cli-proxy-api /CLIProxyAPI/CLIProxyAPI -no-browser --codex-login

  1. Qwen

docker compose exec cli-proxy-api /CLIProxyAPI/CLIProxyAPI -no-browser --qwen-login ```

複製輸出的 `ssh` 隧道命令,**在本地電腦終端**執行(替換實際 SSH 端口):

```bash ssh -p 你的SSH端口 -R 1455:localhost:1455 root@伺服器IP ```

然後在伺服器終端複製授權連結 → 本地瀏覽器打開 → 登錄授權 → 認證文件自動保存。


    1. 七、客戶端使用

| 項目 | 值 | | ------------ | -------------------------------------- | | API Endpoint | `https://xxx.com` | | API Key | `config.yaml` 中 `api-keys` 里設置的值 |


    1. 八、常用運維命令

```bash cd ~/CLIProxyAPI

  1. 查看運行狀態

docker compose ps

  1. 實時日誌

tail -f ./logs/main.log

  1. 重啟服務

docker compose restart

  1. 升級到最新版

docker compose pull && docker compose up -d

  1. 停止服務

docker compose down ```


    1. 各端口說明

| 端口 | 用途 | 是否公網 | | ------- | ----------------------- | ---------------- | | `8317` | 主 API 服務 | 否(Nginx 代理) | | `8085` | 內部端口 | 否 | | `1455` | Claude/Codex OAuth 回調 | ✅ 必須 | | `54545` | Gemini CLI OAuth 回調 | ✅ 必須 | | `51121` | Antigravity OAuth 回調 | ✅ 必須 | | `11451` | 其他 OAuth 回調 | ✅ 必須 |