标签 AWS EC2 下的文章

上篇搭了个 HTTPS 入口,这篇继续部署 CLIProxyAPI 作为 API 网关,让 Claude Code 能用上更多模型。

架构

走 Cloudflare 橙云代理,源站跑 Docker。

部署

写了个一键脚本:CLIProxyAPI AWS EC2 一键部署脚本・GitHub

准备工作:

  • EC2 能 SSH、有 sudo

  • Cloudflare DNS A 记录指向 EC2 IP,开橙云

  • 安全组放行 2096

执行:

 # 下载脚本 mkdir -p ~/cli-proxy && cd ~/cli-proxy

curl -fsSLO https://gist.githubusercontent.com/xrf9268-hue/18c81e1c5225aa2e6541a52deeabbe82/raw/cli-proxy-setup.sh

curl -fsSLO https://gist.githubusercontent.com/xrf9268-hue/18c81e1c5225aa2e6541a52deeabbe82/raw/cli-proxy-config.yaml

curl -fsSLO https://gist.githubusercontent.com/xrf9268-hue/18c81e1c5225aa2e6541a52deeabbe82/raw/cli-proxy-docker-compose.yml

# 执行安装 chmod +x cli-proxy-setup.sh

./cli-proxy-setup.sh install --domain your.domain.com

脚本会自动装 Docker、生成自签证书、随机 API Key、拉镜像起服务。Key 会打印在屏幕上,记一下。

Provider 登录

部分 Provider 需要 OAuth 登录。回调端口只绑 127.0.0.1,得用 SSH 通道。

 # 开通道(保持不关)

ssh -L 51121:127.0.0.1:51121 <user>@<host>

# 在通道里执行登录(以 antigravity 为例) sudo docker compose -f ~/CLIProxyAPI/docker-compose.yml exec cli-proxy-api ./CLIProxyAPI --antigravity-login --no-browser

会输出授权链接,本地浏览器打开、登录、授权完成。

Claude Code 配置

 export ANTHROPIC_BASE_URL="https://your.domain.com:2096" export ANTHROPIC_AUTH_TOKEN="你的key" export ANTHROPIC_DEFAULT_OPUS_MODEL="gemini-claude-opus-4-5-thinking" export ANTHROPIC_DEFAULT_SONNET_MODEL="gemini-claude-sonnet-4-5-thinking" export ANTHROPIC_DEFAULT_HAIKU_MODEL="gemini-claude-sonnet-4-5" 

测试:

 # 用 jq 格式化

curl "https://your.domain.com:2096/v1/models" -H "Authorization: Bearer 你的key" | jq

# 或用 python

curl "https://your.domain.com:2096/v1/models" -H "Authorization: Bearer 你的key" | python3 -m json.tool

能返回模型列表就成了。


📌 转载信息
转载时间:
2026/1/20 17:38:37