中国站
帮助中心 > 计算 > 云服务器 > 最佳实践 > 建站教程 > openclaw新版部署教程

openclaw新版部署教程

OpenClaw 是一个开源的个人AI 助手平台,支持通过多种消息渠道与AI 交互,支持通过WhatsApp、飞书、Telegram 、qq、微信等常用聊天软件交互,能实现邮件发送、日程管理。

linux服务器中部署

安装

如需要安装最新版本openclaw请选择ubuntu22.04 LTS 64位系统,或者选择openclaw镜像。

执行命令安装:

  1. curl -fsSL https://openclaw.ai/install.sh | bash

配置网关

安装完后再配置AI:

  1. openclaw onboard











配置完成后还不能访问,需要再修改配置文件

  1. 先执行以下命令,再修改配置文件
  2. NEW_TOKEN=$(openssl rand -base64 32)
  3. openclaw config set gateway.auth.token "$NEW_TOKEN" #设置token
  4. openclaw config set gateway.controlUi.allowInsecureAuth true #设置允许http访问
  5. openclaw config set gateway.controlUi.dangerouslyDisableDeviceAuth true #设置安全降低
  6. openclaw config set gateway.bind "lan" #设置外网访问
  7. openclaw config set gateway.mode "local"
  8. 开启最大权限
  9. openclaw config set tools.profile full
  10. openclaw config set tools.deny '[]' --json
  11. openclaw config unset tools.allow
  12. openclaw config set agents.defaults.sandbox.mode off
  13. #再核对配置文件,http://localhost:18789 localhost需要改成ip
  14. vi /root/.openclaw/openclaw.json
  15. #修改完成后,执行重启网关
  16. openclaw gateway restart
  17. #再访问http://ip:18789/
  18. #查询token
  19. cat /root/. openclaw/openclaw.json | grep token #打印token


配置插件

如果还需要安装微信聊天

  1. openclaw plugins install @openclaw-china/dingtalk
  2. openclaw china setup
  3. openclaw plugins install @openclaw-china/dingtalk
  4. openclaw china setup
  5. openclaw plugins install @openclaw-china/feishu-china
  6. openclaw china setup
  7. openclaw plugins install @openclaw-china/qqbot
  8. openclaw china setup
  9. openclaw plugins install @openclaw-china/wecom-app
  10. openclaw china setup
  11. openclaw plugins install @openclaw-china/wecom
  12. openclaw china setup

配置https(新版本必须配置)

1、修改DOMAIN
2、 执行脚本

  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # =========================
  4. # 可修改变量
  5. # =========================
  6. DOMAIN="your-domain.com"
  7. OPENCLAW_PORT="18789"
  8. CERT_DIR="/etc/nginx/cert"
  9. NGINX_CONF="/etc/nginx/conf.d/openclaw.conf"
  10. # 证书主题信息
  11. C="CN"
  12. ST="GuangDong"
  13. L="ShenZhen"
  14. O="OpenClaw"
  15. OU="IT"
  16. CN="${DOMAIN}"
  17. # =========================
  18. # 检查 root
  19. # =========================
  20. if [ "$(id -u)" -ne 0 ]; then
  21. echo "请使用 root 运行此脚本"
  22. exit 1
  23. fi
  24. echo "[1/7] 安装 nginx 和 openssl ..."
  25. if command -v apt >/dev/null 2>&1; then
  26. apt update
  27. apt install -y nginx openssl
  28. elif command -v yum >/dev/null 2>&1; then
  29. yum install -y epel-release || true
  30. yum install -y nginx openssl
  31. elif command -v dnf >/dev/null 2>&1; then
  32. dnf install -y nginx openssl
  33. else
  34. echo "不支持的系统包管理器,请手动安装 nginx 和 openssl"
  35. exit 1
  36. fi
  37. echo "[2/7] 创建证书目录 ..."
  38. mkdir -p "${CERT_DIR}"
  39. chmod 700 "${CERT_DIR}"
  40. echo "[3/7] 生成私钥 private.key ..."
  41. openssl ecparam -genkey -name prime256v1 -out "${CERT_DIR}/private.key"
  42. echo "[4/7] 生成 CSR cert.csr ..."
  43. openssl req \
  44. -new \
  45. -key "${CERT_DIR}/private.key" \
  46. -out "${CERT_DIR}/cert.csr" \
  47. -subj "/C=${C}/ST=${ST}/L=${L}/O=${O}/OU=${OU}/CN=${CN}"
  48. echo "[5/7] 生成自签名证书 cert.pem ..."
  49. openssl x509 \
  50. -req \
  51. -days 3650 \
  52. -in "${CERT_DIR}/cert.csr" \
  53. -signkey "${CERT_DIR}/private.key" \
  54. -out "${CERT_DIR}/cert.pem"
  55. chmod 600 "${CERT_DIR}/private.key"
  56. chmod 644 "${CERT_DIR}/cert.pem"
  57. chmod 644 "${CERT_DIR}/cert.csr"
  58. echo "[6/7] 写入 nginx 配置 ..."
  59. mkdir -p /etc/nginx/conf.d
  60. cat > "${NGINX_CONF}" <<EOF
  61. map \$http_upgrade \$connection_upgrade {
  62. default upgrade;
  63. '' close;
  64. }
  65. server {
  66. listen 80;
  67. server_name ${DOMAIN};
  68. return 301 https://\$host\$request_uri;
  69. }
  70. server {
  71. listen 443 ssl http2;
  72. server_name ${DOMAIN};
  73. ssl_certificate ${CERT_DIR}/cert.pem;
  74. ssl_certificate_key ${CERT_DIR}/private.key;
  75. ssl_session_timeout 1d;
  76. ssl_session_cache shared:SSL:10m;
  77. ssl_session_tickets off;
  78. ssl_protocols TLSv1.2 TLSv1.3;
  79. ssl_prefer_server_ciphers off;
  80. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
  81. add_header X-Frame-Options "SAMEORIGIN" always;
  82. add_header X-Content-Type-Options "nosniff" always;
  83. add_header Referrer-Policy "strict-origin-when-cross-origin" always;
  84. access_log /var/log/nginx/openclaw-access.log;
  85. error_log /var/log/nginx/openclaw-error.log;
  86. location / {
  87. proxy_pass http://127.0.0.1:${OPENCLAW_PORT};
  88. proxy_http_version 1.1;
  89. proxy_set_header Upgrade \$http_upgrade;
  90. proxy_set_header Connection \$connection_upgrade;
  91. proxy_set_header Host \$host;
  92. proxy_set_header X-Real-IP \$remote_addr;
  93. proxy_set_header X-Forwarded-For \$remote_addr;
  94. proxy_set_header X-Forwarded-Proto \$scheme;
  95. proxy_set_header X-Forwarded-Host \$host;
  96. proxy_connect_timeout 60s;
  97. proxy_send_timeout 60s;
  98. proxy_read_timeout 86400s;
  99. proxy_buffering off;
  100. }
  101. }
  102. EOF
  103. # 有些系统默认站点会冲突,尝试移除
  104. if [ -f /etc/nginx/sites-enabled/default ]; then
  105. rm -f /etc/nginx/sites-enabled/default
  106. fi
  107. if [ -f /etc/nginx/conf.d/default.conf ]; then
  108. rm -f /etc/nginx/conf.d/default.conf
  109. fi
  110. echo "[7/7] 检查并启动 nginx ..."
  111. nginx -t
  112. systemctl enable nginx
  113. systemctl restart nginx
  114. echo
  115. echo "安装完成"
  116. echo "域名: ${DOMAIN}"
  117. echo "证书目录: ${CERT_DIR}"
  118. echo "Nginx 配置: ${NGINX_CONF}"
  119. echo
  120. echo "证书文件:"
  121. echo " 私钥: ${CERT_DIR}/private.key"
  122. echo " CSR : ${CERT_DIR}/cert.csr"
  123. echo " 证书: ${CERT_DIR}/cert.pem"
  124. echo
  125. echo "访问地址: https://${DOMAIN}"
  126. echo
  127. echo "注意:"
  128. echo "1. 这是自签名证书,浏览器会提示不受信任"
  129. echo "2. 请确认域名 ${DOMAIN} 已解析到当前服务器"
  130. echo "3. 请确认 OpenClaw 已监听 127.0.0.1:${OPENCLAW_PORT}"

2、 配置allowedOrigins

  1. {
  2. "gateway": {
  3. "port": 18789,
  4. "mode": "local",
  5. "bind": "loopback",
  6. "trustedProxies": ["127.0.0.1", "::1"],
  7. "auth": {
  8. "mode": "token",
  9. "token": "your-very-strong-random-token-here"
  10. },
  11. "controlUi": {
  12. "allowedOrigins": ["https://your-domain.com"]
  13. }
  14. }
  15. }