OpenClaw 腾讯云服务本地访问配置指南

本文介绍如何在腾讯云服务器上配置 OpenClaw 服务,通过 Nginx 反向代理实现公网访问。


目录


1. 安装 Nginx

根据你的发行版执行对应命令:

Ubuntu / Debian

sudo apt install -y nginx

CentOS / RHEL

sudo yum install -y nginx

启动并设置开机自启

sudo systemctl start nginx
sudo systemctl enable nginx

2. 创建 Nginx 配置文件

创建配置文件:

sudo vim /etc/nginx/sites-available/openclaw.conf

将以下内容粘贴进去,替换 your-domain.com 为你自己的域名:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://127.0.0.1:18789;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;

        # 超时设置
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }
}

3. 启用配置并测试

创建软链接

sudo ln -s /etc/nginx/sites-available/openclaw.conf /etc/nginx/sites-enabled/

测试配置正确性

sudo nginx -t

如果输出显示 test is successful,说明配置没问题,执行重载:

sudo systemctl reload nginx

4. 配置 OpenClaw 可信代理

编辑 OpenClaw 配置文件 ~/.openclaw/openclaw.json,在 gateway 区块下添加/修改以下配置:

{
  "gateway": {
    "port": 18789,
    "mode": "local",
    "bind": "lan",
    "trustedProxies": ["127.0.0.1"],
    "controlUi": {
      "allowedOrigins": [
        "http://localhost:18789",
        "http://127.0.0.1:18789",
        "http://你的服务器IP:18789",
        "https://www.your-domain.com",
        "https://your-domain.com"
      ],
      "dangerouslyDisableDeviceAuth": true,
      "allowInsecureAuth": true
    }
  }
}

根据实际情况修改 allowedOrigins 中的域名和IP列表,添加你自己的访问地址。

修改配置后需要重启 OpenClaw 服务生效:

openclaw gateway restart

5. 配置防火墙

登录腾讯云控制台,在安全组中开放 80 (HTTP) 和 443 (HTTPS) 端口。

如果服务器本地也启用了 ufwfirewalld,也需要同步开放这两个端口:

ufw (Ubuntu/Debian):

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

6. 配置 HTTPS 证书

使用 Certbot 申请免费的 Let’s Encrypt 证书:

安装 Certbot

sudo apt install -y certbot python3-certbot-nginx

申请证书并自动配置 Nginx

sudo certbot --nginx -d your-domain.com

按照提示完成操作,Certbot 会自动修改 Nginx 配置并启用 HTTPS。

测试自动续期

Let’s Encrypt 证书有效期为 90 天,Certbot 一般会自动续期。你可以手动测试:

sudo certbot renew --dry-run

完成以上步骤后,就可以通过 https://你的域名 公网访问部署在腾讯云上的 OpenClaw 服务了。

Logo

小龙虾开发者社区是 CSDN 旗下专注 OpenClaw 生态的官方阵地,聚焦技能开发、插件实践与部署教程,为开发者提供可直接落地的方案、工具与交流平台,助力高效构建与落地 AI 应用

更多推荐