---
url: /host/8xw5miat/index.md
description: >-
  使用 Docker Compose 同时部署 CLI Proxy API（CPA）及其增强管理面板 CPA Manager Plus（CPAMP），通过
  Nginx 统一反代实现 API 转发与面板管理。
---
本文讲解如何使用 Docker Compose 同时部署 [CLI Proxy API](https://github.com/router-for-me/CLIProxyAPI)（简称 **CPA**）与其增强管理面板 [CPA Manager Plus](https://github.com/router-for-me/Cli-Proxy-API-Management-Center)（简称 **CPAMP**），并通过 Nginx 统一反代，对外仅暴露一个端口。

* **CPA（CLI Proxy API）**：统一代理转发 Claude Code、Codex、Gemini 等 CLI 工具的请求，支持多模型与 OAuth 账号管理。
* **CPAMP（CPA Manager Plus）**：CPA 的增强管理面板，提供用量统计、模型价格管理、API 密钥别名、请求监控、Codex 账号巡检与导入导出等功能。

部署后共三个容器协同工作，最终目录结构如下：

::: file-tree

* 项目目录
  * `config.yaml` CPA 配置文件
  * `docker-compose.yaml` 编排文件
  * nginx
    * conf.d
      * `default.conf` Nginx 反代配置
  * `auths/` CPA 认证数据（运行后自动生成）
  * `logs/` CPA 日志（运行后自动生成）
  * `cpa-manager-plus-data/` CPAMP 数据（运行后自动生成）
    :::

## 1. 下载默认配置文件

```shell
wget https://raw.githubusercontent.com/router-for-me/CLIProxyAPI/main/config.example.yaml
cp config.example.yaml config.yaml
```

## 2. 修改配置文件 config.yaml

```yaml
# Management API settings
remote-management:
  # Whether to allow remote (non-localhost) management access.
  # When false, only localhost can access management endpoints (a key is still required).
  allow-remote: true # 允许远程访问

  # Management key. If a plaintext value is provided here, it will be hashed on startup.
  # All management requests (even from localhost) require this key.
  # Leave empty to disable the Management API entirely (404 for all /v0/management routes).
  secret-key: "123321" # 设置一个自己的密钥 key，如果不设置，会自动生成

  # Disable the bundled management control panel asset download and HTTP route when true.
  disable-control-panel: false

  # Disable automatic periodic background updates of the management panel from GitHub (default: false).
  # When enabled, the panel is only downloaded on first access if missing, and never auto-updated afterward.
  # disable-auto-update-panel: false

  # GitHub repository for the management control panel. Accepts a repository URL or releases API URL.
  panel-github-repository: "https://github.com/router-for-me/Cli-Proxy-API-Management-Center"

# Authentication directory (supports ~ for home directory)
auth-dir: "~/.cli-proxy-api"

# API keys for authentication
# 这里最好不使用默认的 不然可能会进不去
api-keys:
  - "123"
```

::: warning 密钥说明

* `config.yaml` 中的 `remote-management.secret-key` 是 **CPA 管理 API** 的访问密钥。
* `docker-compose.yaml` 中的 `CPA_MANAGER_ADMIN_KEY` 是 **CPAMP 面板** 的登录密钥。
* 两者用途不同，示例中均为 `123321` 仅为演示，生产环境请使用不同的强随机密钥。
  :::

## 3. 创建 Nginx 配置文件

```shell
mkdir -p ./nginx/conf.d
touch ./nginx/conf.d/default.conf
vim ./nginx/conf.d/default.conf
# 编辑内容如下
```

```nginx
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

upstream cpa_api {
    server cli-proxy-api:8317;
}

upstream cpamp {
    server cpa-manager-plus:18317;
}

server {
    listen 80;
    # 如有域名请改成 your-domain.com；用 IP:20831 直连时 _ 可通配
    server_name _;

    client_max_body_size 64m;

    proxy_http_version 1.1;
    proxy_read_timeout 3600s;
    proxy_send_timeout 3600s;
    proxy_buffering off;

    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;
    proxy_set_header Upgrade           $http_upgrade;
    proxy_set_header Connection        $connection_upgrade;

    # 默认进入 CPAMP 面板
    location = / {
        return 302 /management.html;
    }

    # ===== CPA Manager Plus =====

    location = /management.html { proxy_pass http://cpamp; }
    location = /health          { proxy_pass http://cpamp; }
    location = /status          { proxy_pass http://cpamp; }
    location = /setup           { proxy_pass http://cpamp; }

    # CPAMP 兼容接口与运行时接口
    location ^~ /usage-service/ { proxy_pass http://cpamp; }

    # /v0/management/* 先进入 CPAMP：
    # - 用量 / 模型价格 / API 密钥别名 / 仪表盘 / 请求监控 /
    #   Codex 账号巡检 / 导入导出 等由 CPAMP 自己处理
    # - 其他 CPA 管理接口由 CPAMP 使用服务端保存的 CPA Management Key 继续代理到 CPA
    #
    # 注意：不要只配置 location = /v0/management
    # 应使用带尾斜杠的前缀匹配 /v0/management/
    location ^~ /v0/management/ { proxy_pass http://cpamp; }

    # CPAMP 插件页面资源。缺少此规则时，插件页面可能打开空白或资源 404。
    location ^~ /v0/resource/plugins/ { proxy_pass http://cpamp; }

    # /models 由 CPAMP 提供兼容代理
    # 如果 CPAMP 尚未完成 setup，访问此路径可能返回 412
    location = /models          { proxy_pass http://cpamp; }

    # ===== CPA / CLI Proxy API =====

    # OpenAI / Claude Code / Codex 等实际 API 请求应直接走 CPA
    location ^~ /v1/                 { proxy_pass http://cpa_api; }
    location ^~ /v1beta/             { proxy_pass http://cpa_api; }
    location ^~ /backend-api/codex/  { proxy_pass http://cpa_api; }
    location ^~ /api/                { proxy_pass http://cpa_api; }

    # CPA 特殊路由与 OAuth 回调
    location = /v1internal:method    { proxy_pass http://cpa_api; }
    location = /healthz              { proxy_pass http://cpa_api; }
    location = /anthropic/callback   { proxy_pass http://cpa_api; }
    location = /codex/callback       { proxy_pass http://cpa_api; }
    location = /google/callback      { proxy_pass http://cpa_api; }
    location = /antigravity/callback { proxy_pass http://cpa_api; }

    # 兜底给 CPA
    # 用于 CPA 根路径、Amp 路由以及未来新增接口
    location / {
        proxy_pass http://cpa_api;
    }
}
```

## 4. 创建 docker-compose.yaml 文件

```yaml
services:
  cli-proxy-api:
    image: eceasy/cli-proxy-api:latest
    container_name: cli-proxy-api
    restart: unless-stopped
    volumes:
      - ${CLI_PROXY_CONFIG_PATH:-./config.yaml}:/CLIProxyAPI/config.yaml
      - ${CLI_PROXY_AUTH_PATH:-./auths}:/root/.cli-proxy-api
      - ${CLI_PROXY_LOG_PATH:-./logs}:/CLIProxyAPI/logs
    expose:
      - "8317"

  cpa-manager-plus:
    image: seakee/cpa-manager-plus:latest
    container_name: cpa-manager-plus
    restart: unless-stopped
    environment:
      HTTP_ADDR: "0.0.0.0:18317"
      USAGE_DB_PATH: "/data/usage.sqlite"
      CPA_MANAGER_DATA_KEY_PATH: "/data/data.key"
      # 托管部署建议显式设置 这里配置的是 CPAMP 的登录密钥
      CPA_MANAGER_ADMIN_KEY: "123321"
      USAGE_COLLECTOR_MODE: "auto"
      USAGE_BATCH_SIZE: "100"
      USAGE_POLL_INTERVAL_MS: "500"
      USAGE_QUERY_LIMIT: "50000"
    volumes:
      - ./cpa-manager-plus-data:/data
    expose:
      - "18317"
    depends_on:
      - cli-proxy-api

  nginx:
    image: nginx:alpine
    container_name: cpa-nginx
    restart: unless-stopped
    ports:
      - "10086:80"
      # 如果使用 HTTPS，可以再暴露 443。
      # - "443:443"
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d:ro
      # 如果使用 HTTPS，挂载证书目录。
      # - ./nginx/ssl:/etc/nginx/ssl:ro
    depends_on:
      - cli-proxy-api
      - cpa-manager-plus
```

::: tip 端口说明
Nginx 对外暴露 `10086` 端口，如需更改或与现有服务冲突，修改 `ports: - "10086:80"` 中的前半部分即可。CPA 与 CPAMP 通过 `expose` 仅在 Docker 网络内部通信，无需对外暴露。
:::

## 5. 启动

```shell
docker compose up -d
```

## 6. 访问

浏览器打开 `http://your-domain-or-ip:10086/`，会自动跳转到 CPAMP 面板 `management.html`，按引导完成初始化即可。

::: tip 初始化
首次进入面板需完成 setup，其中会要求填写 CPA 的 Management Key（即 `config.yaml` 中的 `secret-key`），填写后 CPAMP 即可代理调用 CPA 的管理接口。
:::
