Skip to main content
Back to Blog
February 13, 202610 min readTemporal Zenith

腾讯云 Ubuntu 配置 V2RayA + OpenClaw:代理 Google API 同时直连飞书

DevOpsOpenClawProxyGuide

场景:这台服务器上运行着 OpenClaw 并对接了飞书(Feishu)。 目标:让 OpenClaw 的对外请求(如调用 Google Gemini/OpenAI)走代理,但飞书 API 请求必须直连(避免鉴权失败或长连接断开)。


1. 准备工作

请先下载以下文件并上传到服务器目录(示例:/root/tmp/):

  1. v2rayA Linux x64(如 v2raya_linux_x64_2.2.x
  2. Xray Core(如 xray-linux-64.zip
  3. GeoDatageoip.datgeosite.dat

2. 安装 Xray 与 GeoData

# 创建目录
sudo mkdir -p /usr/local/bin /usr/local/share/xray
cd /root/tmp

# 安装 Xray
sudo unzip xray-linux-64.zip -d /usr/local/bin/
sudo chmod +x /usr/local/bin/xray
/usr/local/bin/xray version

# 放置 Geo 数据
sudo cp geoip.dat geosite.dat /usr/local/share/xray/
ls -la /usr/local/share/xray | egrep 'geo(ip|site)\.dat'

3. 安装 v2rayA 并配置服务

v2rayA 提供可视化面板,方便管理节点。

cd /root/tmp
sudo cp v2raya_linux_x64_2.2.7.5 /usr/local/bin/v2raya
sudo chmod +x /usr/local/bin/v2raya

# 创建系统服务
sudo tee /etc/systemd/system/v2raya.service >/dev/null <<'UNIT'
[Unit]
Description=v2rayA Service
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/local/bin/v2raya
Environment="V2RAYA_V2RAY_BIN=/usr/local/bin/xray"
Environment="XRAY_LOCATION_ASSET=/usr/local/share/xray"
Restart=on-failure
RestartSec=1

[Install]
WantedBy=multi-user.target
UNIT

# 启动服务
sudo systemctl daemon-reload
sudo systemctl enable --now v2raya

4. 访问 v2rayA 面板

面板默认运行在 2017 端口。推荐使用 SSH 隧道访问,避免暴露面板到公网。

本地终端执行:

ssh -L 2017:127.0.0.1:2017 root@<服务器IP>

浏览器访问: http://127.0.0.1:2017

在面板中:

  1. 导入你的节点/订阅。
  2. 选择节点并启动。
  3. 设置建议
    • 防止 DNS 污染:开启
    • 透明代理:不需要(我们只用端口)

5. (推荐) 启用本地稳定代理端口:xray-proxy

v2rayA 的端口可能会随配置变动。为了生产环境稳定,建议运行一个独立的 Xray 实例,提供固定的本地代理端口。

端口定义

  • SOCKS5: 127.0.0.1:20170
  • HTTP: 127.0.0.1:20171

5.1 写入配置 /etc/xray-proxy.json

⚠️ 注意:请务必修改下方的 address, port, id 你的节点信息!

sudo tee /etc/xray-proxy.json >/dev/null <<'JSON'
{
  "log": {"loglevel": "warning"},
  "inbounds": [
    {"tag": "socks-in", "listen": "127.0.0.1", "port": 20170, "protocol": "socks", "settings": {"auth": "noauth", "udp": true}},
    {"tag": "http-in",  "listen": "127.0.0.1", "port": 20171, "protocol": "http",  "settings": {"timeout": 300}}
  ],
  "outbounds": [
    {
      "tag": "proxy",
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "api.your-provider.com",
            "port": 443,
            "users": [
              {"id": "你的UUID-UUID-UUID-UUID", "security": "auto", "alterId": 0}
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "security": "tls",
        "tlsSettings": {"serverName": "api.your-provider.com"},
        "wsSettings": {"path": "/path", "headers": {"Host": "api.your-provider.com"}}
      }
    },
    {"tag": "direct", "protocol": "freedom"},
    {"tag": "block", "protocol": "blackhole"}
  ],
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "rules": [
      {"type": "field", "inboundTag": ["socks-in", "http-in"], "outboundTag": "proxy"}
    ]
  }
}
JSON

5.2 启动本地代理服务

sudo tee /etc/systemd/system/xray-proxy.service >/dev/null <<'UNIT'
[Unit]
Description=Xray Local Proxy (Fixed Ports 20170/20171)
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/bin/xray run -config /etc/xray-proxy.json
Restart=on-failure
RestartSec=1
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
UNIT

sudo systemctl daemon-reload
sudo systemctl enable --now xray-proxy

5.3 验证代理可用性

# 测试 Google(应该返回 200 或 301)
curl -I -m 5 -x http://127.0.0.1:20171 https://www.google.com

# 检查端口监听
ss -ltnp | egrep ':(20170|20171)'

6. 配置 OpenClaw 服务(核心步骤)

为了让 OpenClaw 既能访问 Google 又能直连飞书,我们需要通过环境变量精确控制:

  1. HTTP_PROXY / HTTPS_PROXY: 指向本地代理 http://127.0.0.1:20171
  2. NO_PROXY: 排除 本地地址和飞书域名。

修改 OpenClaw 服务文件

sudo tee /etc/systemd/system/openclaw-gateway.service >/dev/null <<'UNIT'
[Unit]
Description=OpenClaw Gateway
After=network-online.target

[Service]
Type=simple
User=root
WorkingDirectory=/root

# 1. 设置代理(指向 xray-proxy 端口)
Environment="HTTP_PROXY=http://127.0.0.1:20171"
Environment="HTTPS_PROXY=http://127.0.0.1:20171"

# 2. 关键:设置直连白名单
# 注意:使用 .feishu.cn 格式比 *.feishu.cn 兼容性更好
Environment="NO_PROXY=localhost,127.0.0.1,::1,.feishu.cn,.feishuapis.com,open.feishu.cn"

# 启动命令(根据你的实际安装路径调整)
ExecStart=/usr/local/bin/node /usr/local/lib/node_modules/openclaw/dist/index.js gateway --port 18789

Restart=on-failure
RestartSec=3

[Install]
WantedBy=multi-user.target
UNIT

重启 OpenClaw 并验证

sudo systemctl daemon-reload
sudo systemctl restart openclaw-gateway

# 查看日志,确认无报错,且飞书连接正常
journalctl -u openclaw-gateway -f

7. 总结

  • 常规流量(系统更新、curl等):默认直连,不走代理。
  • OpenClaw 流量
    • 访问 Google/OpenAI -> 走 127.0.0.1:20171 -> 代理。
    • 访问飞书 (.feishu.cn) -> 命中 NO_PROXY -> 直连
    • 访问本地数据库 -> 命中 localhost -> 直连

这样既解决了 API 墙的问题,又避免了飞书因为 IP 变动或代理不稳定导致的连接问题。

Ready to Try It Yourself?

PDFLocal offers 90+ free PDF tools that run entirely in your browser.

PDFLocal

Professional PDF Tools - Free & Private

Security

  • Client-side processingFiles never leave your device
  • No file uploads100% private & secure

Compliance

GDPR Compliant
100% Private - Files never leave your device
Select Language

© 2026 PDFLocal. © PDFLocal. All rights reserved.