Skip to content
广告 · 本站推荐广告

国内网络配置

本指南帮助中国大陆用户解决 OpenClaw 使用中的网络访问问题,配置代理和镜像加速。

哪些服务需要代理?

一览表

根据你的使用场景,部分服务可能需要代理(Proxy)才能从大陆访问。

服务类型示例是否需要代理
国产模型 APIDeepSeek、Qwen、Moonshot、GLM❌ 不需要
国内通道企业微信、钉钉、飞书❌ 不需要
npm 安装(使用国内镜像)registry.npmmirror.com❌ 不需要
Docker 镜像(使用国内镜像)阿里/腾讯镜像仓库❌ 不需要
海外模型 APIOpenAI、Anthropic、Google✅ 需要
海外通道Telegram、Slack、Discord✅ 需要
GitHub 访问代码拉取、Issue 提交⚠️ 视情况而定

纯国内方案

如果只使用国产模型 + 国内通道,完全不需要配置代理,可以跳过代理相关章节。

代理配置

系统级代理

设置 HTTP_PROXY / HTTPS_PROXY 环境变量:

bash
# 临时设置(当前会话有效)
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
export NO_PROXY=localhost,127.0.0.1,.deepseek.com,.aliyuncs.com,.tencent.com,.baidu.com

# 永久设置(写入 ~/.bashrc 或 ~/.zshrc)
echo 'export HTTP_PROXY=http://127.0.0.1:7890' >> ~/.bashrc
echo 'export HTTPS_PROXY=http://127.0.0.1:7890' >> ~/.bashrc
echo 'export NO_PROXY=localhost,127.0.0.1,.deepseek.com,.aliyuncs.com,.tencent.com,.baidu.com' >> ~/.bashrc
source ~/.bashrc
bash
# 在 OpenClaw 根目录的 .env 文件中配置
HTTP_PROXY=http://127.0.0.1:7890
HTTPS_PROXY=http://127.0.0.1:7890
NO_PROXY=localhost,127.0.0.1,.deepseek.com,.aliyuncs.com,.tencent.com,.baidu.com

NO_PROXY 很重要

务必在 NO_PROXY 中排除国产模型和国内服务的域名,避免国内流量走代理导致变慢或出错。

Node.js 级代理

如果系统级代理不生效,可以使用 global-agent 在 Node.js 层面设置代理:

bash
# 安装 global-agent
npm install -g global-agent

# 在启动前设置
export GLOBAL_AGENT_HTTP_PROXY=http://127.0.0.1:7890
openclaw start

Docker 代理配置

Docker 环境下需要额外配置 daemon(守护进程)代理:

json
// /etc/docker/daemon.json
{
  "proxies": {
    "http-proxy": "http://127.0.0.1:7890",
    "https-proxy": "http://127.0.0.1:7890",
    "no-proxy": "localhost,127.0.0.1,.aliyuncs.com,.tencent.com"
  }
}
bash
# 重启 Docker 使配置生效
sudo systemctl restart docker

也可以在 docker run 时指定容器级代理:

bash
docker run -d \
  -e HTTP_PROXY=http://host.docker.internal:7890 \
  -e HTTPS_PROXY=http://host.docker.internal:7890 \
  -e NO_PROXY=localhost,.deepseek.com,.aliyuncs.com \
  registry.cn-hangzhou.aliyuncs.com/openclaw/openclaw:latest

通道级代理

为特定通道单独配置代理(仅海外通道需要):

yaml
# config.yaml
channels:
  telegram:
    enabled: true
    token: "your-bot-token"
    proxy: "http://127.0.0.1:7890"  # 仅 Telegram 使用代理
  wecom:
    enabled: true
    corpId: "your-corp-id"
    # 企业微信无需代理,不配置 proxy 字段

镜像源加速

npm 镜像

bash
# 设置为国内镜像(npmmirror,原淘宝镜像)
npm config set registry https://registry.npmmirror.com

# 验证镜像是否生效
npm config get registry

# 临时使用(不修改全局配置)
npm install --registry https://registry.npmmirror.com

Docker 镜像

使用国内镜像仓库拉取 OpenClaw 镜像:

bash
docker pull registry.cn-hangzhou.aliyuncs.com/openclaw/openclaw:latest
bash
docker pull mirror.ccs.tencentyun.com/openclaw/openclaw:latest

配置 Docker Hub 镜像加速器:

json
// /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://mirror.ccs.tencentyun.com",
    "https://docker.mirrors.ustc.edu.cn"
  ]
}

GitHub 加速

bash
# 使用 CNB 镜像克隆代码
git clone https://cnb.cool/openclaw_ai/openclaw.git

# 或使用 ghproxy 加速 GitHub 下载
wget https://ghproxy.com/https://github.com/openclaw/openclaw/archive/main.zip

云服务商内网加速

阿里云 VPC 内网

在阿里云 ECS 上访问阿里云的服务(如 DashScope API)时,可使用内网 Endpoint(端点)降低延迟:

yaml
# config.yaml - 阿里云内网 endpoint
models:
  dashscope:
    endpoint: "https://dashscope-intl.aliyuncs.com"  # 内网端点
    apiKey: "${DASHSCOPE_API_KEY}"

腾讯云 VPC 内网

腾讯云 CVM 访问腾讯云 AI 服务同样可以使用内网地址,减少网络跳数和延迟。

网络问题排查

诊断命令

bash
# 测试国内模型连通性
curl -v https://api.deepseek.com/v1/models

# 测试海外模型连通性(通过代理)
curl -v --proxy http://127.0.0.1:7890 https://api.openai.com/v1/models

# OpenClaw 内置网络诊断
openclaw doctor --network

常见问题

症状可能原因解决方案
npm install 超时未配置国内镜像设置 npmmirror 镜像源
docker pull 超时未配置镜像加速使用国内镜像仓库
海外模型 API 超时未配置代理设置 HTTP_PROXY
国产模型 API 变慢国内流量走了代理检查 NO_PROXY 配置
GitHub 克隆失败网络不稳定使用 Gitee 镜像或 ghproxy

DNS 污染问题

如果遇到间歇性连接失败,可能是 DNS(域名解析)问题。建议使用可靠的 DNS 服务:

bash
# 使用阿里云公共 DNS
echo "nameserver 223.5.5.5" | sudo tee /etc/resolv.conf
echo "nameserver 223.6.6.6" | sudo tee -a /etc/resolv.conf

基于MIT协议开源 | 内容翻译自 官方文档,同步更新