自定义域名访问OpenClaw / ai #61
通过ssh连接使用OpenClaw有些麻烦,每次都要登录,而且速度很慢。那么,可以直接域名访问、像个网站一样随时使用么?答案是肯定的。
需要三步来完成域名访问OpenClaw。
1. 第一步 域名解析和Nginx反向代理
a. 域名解析
域名(比如是 example.com)解析到远程服务器上,使用certbot安装ssl证书(certbot --nginx)
b. Nginx反向代理
修改 example.conf 文件(/etc/nginx/conf.d)
server_name example.com;
gzip on;
gzip_buffers 4 16k;
gzip_comp_level 6;
gzip_vary on;
# 限制上传文件大小 如果需要上传大文件或模型 建议调大
client_max_body_size 50m;
location / {
proxy_pass http://127.0.0.1:18789;
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_http_version 1.1;
# 【核心】支持 WebSocket 连接 防止AI对话时流式传输或长连接中断
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 超时设置(防止大模型生成回答时间过长导致 Nginx 报 504 超时)
proxy_read_timeout 600s;
proxy_send_timeout 600s;
}
2. 第二步 修改openclaw.json
在远程服务器上打开 OpenClaw 配置文件(通常位于 ~/.openclaw/openclaw.json),有两个位置需要修改。
Loopback 监听模式(即仅绑定在 127.0.0.1 / localhost 上)修改成 lan
"gateway": {
"bind": "lan"
}
controlUi 添加allowedOrigins:
"controlUi": {
"allowedOrigins": [
"http://:18789",
"https://example.com"
]
}
配置好后重启 OpenClaw 服务, openclaw gateway restart
3. 设备授权(首次连接)
首次连接OpenClaw时需要对其授权
openclaw devices list (查看pending状态的)
openclaw devices approve <requestId>
eg: openclaw devices approve bbd82409-f177-4dc2-xxxx-axxxxx
附: 最主要的问题
origin not allowed (open the Control UI from the gateway host or allow it in gateway.controlUi.allowedOrigins)
把它丢给gemini,按它的提示一步步修改直到成功。
使用域名后,速度快了不少,而且打开即用!
Leave 自定义域名访问OpenClaw / ai #61 to:
Read more #cn posts
Best Posts From lemooljiang
We have not curated any of lemooljiang's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.