AI创想

标题: 解决OpenClaw只能本地访问的问题 [打印本页]

作者: 米落枫    时间: 昨天 23:17
标题: 解决OpenClaw只能本地访问的问题
作者:CSDN博客
        OpenClaw 的默认配置是只能在本机上访问,也就是说只能通过 “localhost” 或 “127.0.0.1” 来访问控制台。需要解决该问题有以下四种方式,大家可以根据自己的实际情况来选择。
快速部署安装

       方式一: 详见安装文档
       方式二:推荐方式
方式一:控制台修改

该方式的前提是你能通过浏览器访问到控制台了才行,我这里都是默认配置。
注意事项:
        我这里默认配置是通过 “127.0.0.1” 可以正常访问渲染,可能有的人是 “localhost” 访问是正常的。这个大家可以不用管,是配置的差异问题,不影响操作。
步骤一:访问控制台

        打开地址:http://127.0.0.1:18789/config
(, 下载次数: 0)


步骤二:修改 Setup Wizard 的 Mode

        将默认的 local 改为 remote
(, 下载次数: 0)


步骤三:修改 Gateway 的 Bind

        将默认的 loopback 改为 lan
(, 下载次数: 0)


步骤四:重启 OpenClaw 服务

(, 下载次数: 0)


发现问题:

        这里可能很多人访问后会发现一个问题,页面显示错误:
  1. disconnected (1008): control ui requires HTTPS or localhost (secure context)
复制代码
(, 下载次数: 0)


解决办法:

        修改配置文件 openclaw.json 在配置文件中新增以下内容:
修改前:
  1.   "gateway": {
  2.     "port": 18789,
  3.     "mode": "local",
  4.     "bind": "lan",
  5.     "auth": {
  6.       "mode": "token",
  7.       "token": "6feca87ceb8134d44ea3148b5fb41d1f40fcc9ed0e7920a9"
  8.     },
  9.     "tailscale": {
  10.       "mode": "off",
  11.       "resetOnExit": false
  12.     }
  13.   },
复制代码
修改后:
  1.   "gateway": {
  2.     "port": 18789,
  3.     "mode": "local",
  4.     "bind": "lan",
  5.     // 新增配置
  6.         "controlUi": {
  7.       "allowInsecureAuth": true
  8.     },
  9.     "auth": {
  10.       "mode": "token",
  11.       "token": "6feca87ceb8134d44ea3148b5fb41d1f40fcc9ed0e7920a9"
  12.     },
  13.     "tailscale": {
  14.       "mode": "off",
  15.       "resetOnExit": false
  16.     }
  17.   },
复制代码
方式二:通过命令行修改
  1. # 步骤一:
  2. clawdbot config set gateway.bind lan
  3. # 步骤二
  4. clawdbot config set gateway.controlUi.allowInsecureAuth true
  5. # 步骤三
  6. clawdbot gateway restart
  7. # 备注命令说明
  8. # 指定端口
  9. openclaw gateway --port 19000
  10. # 绑定模式
  11. openclaw gateway --bind loopback   # 仅本机访问(默认,最安全)
  12. openclaw gateway --bind lan        # 局域网可访问
  13. openclaw gateway --bind tailnet    # Tailscale 网络
  14. # 通过 Tailscale 暴露服务
  15. openclaw gateway --tailscale serve   # 内网暴露
  16. openclaw gateway --tailscale funnel  # 公网暴露(需要 Tailscale 账户)
复制代码
方式三:修改配置文件

        路径查看方式,详见下图:
(, 下载次数: 0)


        找到目录:
(, 下载次数: 0)


        我的配置文件示例如下:
  1. {
  2.   "meta": {
  3.     "lastTouchedVersion": "2026.2.2",
  4.     "lastTouchedAt": "2026-02-27T09:17:47.844Z"
  5.   },
  6.   "wizard": {
  7.     "lastRunAt": "2026-02-27T08:55:43.077Z",
  8.     "lastRunVersion": "2026.2.2",
  9.     "lastRunCommand": "onboard",
  10.     "lastRunMode": "remote"
  11.   },
  12.   "auth": {
  13.     "profiles": {
  14.       "deepseek:default": {
  15.         "provider": "deepseek",
  16.         "mode": "api_key"
  17.       }
  18.     }
  19.   },
  20.   "models": {
  21.     "mode": "merge",
  22.     "providers": {
  23.       "deepseek": {
  24.         "baseUrl": "https://api.deepseek.com",
  25.         "api": "openai-completions",
  26.         "models": [
  27.           {
  28.             "id": "deepseek-chat",
  29.             "name": "DeepSeek Chat",
  30.             "reasoning": false,
  31.             "input": [
  32.               "text"
  33.             ],
  34.             "cost": {
  35.               "input": 0.14,
  36.               "output": 0.28,
  37.               "cacheRead": 0,
  38.               "cacheWrite": 0
  39.             },
  40.             "contextWindow": 64000,
  41.             "maxTokens": 4096
  42.           },
  43.           {
  44.             "id": "deepseek-coder",
  45.             "name": "DeepSeek Coder",
  46.             "reasoning": false,
  47.             "input": [
  48.               "text"
  49.             ],
  50.             "cost": {
  51.               "input": 0.14,
  52.               "output": 0.28,
  53.               "cacheRead": 0,
  54.               "cacheWrite": 0
  55.             },
  56.             "contextWindow": 64000,
  57.             "maxTokens": 4096
  58.           }
  59.         ]
  60.       }
  61.     }
  62.   },
  63.   "agents": {
  64.     "defaults": {
  65.       "model": {
  66.         "primary": "deepseek/deepseek-chat"
  67.       },
  68.       "models": {
  69.         "deepseek/deepseek-chat": {
  70.           "alias": "DeepSeek Chat"
  71.         }
  72.       },
  73.       "workspace": "C:\\Users\\user\\.openclaw\\workspace",
  74.       "compaction": {
  75.         "mode": "safeguard"
  76.       },
  77.       "maxConcurrent": 4,
  78.       "subagents": {
  79.         "maxConcurrent": 8
  80.       }
  81.     }
  82.   },
  83.   "messages": {
  84.     "ackReactionScope": "group-mentions"
  85.   },
  86.   "commands": {
  87.     "native": "auto",
  88.     "nativeSkills": "auto"
  89.   },
  90.   "gateway": {
  91.     "port": 18789,
  92.     "mode": "local",
  93.     "bind": "lan",
  94.         "controlUi": {
  95.       "allowInsecureAuth": true
  96.     },
  97.     "auth": {
  98.       "mode": "token",
  99.       "token": "6feca87ceb8134d44ea3148b5fb41d1f40fcc9ed0e7920a9"
  100.     },
  101.     "tailscale": {
  102.       "mode": "off",
  103.       "resetOnExit": false
  104.     }
  105.   },
  106.   "skills": {
  107.     "install": {
  108.       "nodeManager": "pnpm"
  109.     }
  110.   }
  111. }
复制代码

原文地址:https://blog.csdn.net/qq_37165235/article/details/158468009




欢迎光临 AI创想 (http://www.llms-ai.com/) Powered by Discuz! X3.4