Technology Encyclopedia Home >OpenClaw SSL 证书安装:让你的 AI 助手通过 HTTPS 安全访问

OpenClaw SSL 证书安装:让你的 AI 助手通过 HTTPS 安全访问

在前往活动页了解产品、购买轻量服务器(参考腾讯云 OpenClaw 特别优惠)、部署 OpenClaw 后,如果想要通过域名安全访问,配置 SSL 证书是必经之路。本文将详细介绍如何为 OpenClaw 配置 HTTPS。

为什么需要 HTTPS?

  • 数据传输加密:保护用户隐私和敏感信息
  • 身份认证:验证服务器身份,防止钓鱼网站
  • SEO 加分:搜索引擎更青睐 HTTPS 网站
  • 现代浏览器要求:HTTP 会被标记为不安全

腾讯云 SSL 证书获取

方式一:免费证书(推荐)

腾讯云提供免费 SSL 证书:

  1. 登录 腾讯云 SSL 证书控制台
  2. 选择「免费证书」
  3. 申请个人版证书
  4. 验证域名所有权
  5. 下载证书文件

方式二:付费证书

高安全性场景可选择付费证书:

  • 专业版:验证企业身份,安全性更高
  • 增强版:支持中文域名,浏览器兼容性更好

OpenClaw HTTPS 配置

方式一:Nginx 反向代理(推荐)

Nginx 是最常用的反向代理方案:

# docker-compose.yml
version: '3.8'

services:
  nginx:
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./ssl:/etc/nginx/ssl:ro
    depends_on:
      - openclaw
    restart: unless-stopped

  openclaw:
    image: openclaw/openclaw:latest
    expose:
      - "8080"
    restart: unless-stopped

Nginx 配置

# nginx.conf
events {
    worker_connections 1024;
}

http {
    upstream openclaw {
        server openclaw:8080;
    }
    
    server {
        listen 80;
        server_name your-domain.com;
        
        # HTTP 自动跳转 HTTPS
        return 301 https://$server_name$request_uri;
    }
    
    server {
        listen 443 ssl http2;
        server_name your-domain.com;
        
        ssl_certificate /etc/nginx/ssl/fullchain.pem;
        ssl_certificate_key /etc/nginx/ssl/private.key;
        
        # SSL 安全配置
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
        ssl_prefer_server_ciphers off;
        
        # HSTS(可选)
        # add_header Strict-Transport-Security "max-age=31536000" always;
        
        location / {
            proxy_pass http://openclaw;
            proxy_http_version 1.1;
            
            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_set_header X-Forwarded-Proto $scheme;
            
            # WebSocket 支持
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            
            proxy_connect_timeout 60s;
            proxy_send_timeout 60s;
            proxy_read_timeout 60s;
        }
    }
}

方式二:OpenClaw 内置 HTTPS

部分 OpenClaw 版本支持直接配置:

# docker-compose.yml
services:
  openclaw:
    image: openclaw/openclaw:latest
    ports:
      - "8080:8080"
    environment:
      - SSL_ENABLED=true
      - SSL_CERT_PATH=/app/ssl/fullchain.pem
      - SSL_KEY_PATH=/app/ssl/private.key
    volumes:
      - ./ssl:/app/ssl:ro

证书部署步骤

第一步:上传证书文件

在服务器上创建证书目录:

mkdir -p ~/openclaw/ssl
cd ~/openclaw/ssl

# 从腾讯云下载的证书文件
# certificate.pem -> fullchain.pem
# private.key -> private.key

第二步:修改 Nginx 配置

vim ~/openclaw/nginx.conf
# 粘贴上面的配置

第三步:启动服务

cd ~/openclaw
docker-compose up -d

第四步:验证配置

# 检查 Nginx 配置
docker-compose exec nginx nginx -t

# 查看运行状态
docker-compose ps

第五步:测试 HTTPS

# 测试访问
curl -I https://your-domain.com

# 检查证书信息
openssl s_client -connect your-domain.com:443 -servername your-domain.com

证书自动续期

免费证书有效期 90 天,需要定期续期。

方式一:acme.sh 自动续期

# 安装 acme.sh
curl https://get.acme.sh | sh

# 颁发证书
acme.sh --issue -d your-domain.com --dns --yes-I-know-dns-manual-mode-enough-go-ahead

# 安装证书
acme.sh --install-cert -d your-domain.com \
  --key-file /path/to/key.pem \
  --fullchain-file /path/to/fullchain.pem \
  --reloadcmd "docker-compose -f /path/to/docker-compose.yml exec nginx nginx -s reload"

方式二:腾讯云自动续期

腾讯云付费证书支持自动续期,配置后无需手动操作。

常见问题

证书不被信任

  1. 原因:证书链不完整
  2. 解决:使用 fullchain.pem(包含完整证书链)

浏览器显示不安全

  1. 检查:证书是否过期
  2. 检查:域名是否匹配
  3. 检查:是否有 HTTP 资源混用

HTTPS 后 WebSocket 失效

确保配置了 WebSocket 代理:

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

证书文件权限

chmod 600 ~/openclaw/ssl/private.key
chmod 644 ~/openclaw/ssl/fullchain.pem

安全加固建议

1. 启用 HSTS

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

2. 配置安全响应头

add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;

3. 限制 TLS 版本

ssl_protocols TLSv1.2 TLSv1.3;

4. 配置 OCSP Stapling

ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;

测试工具

SSL Labs 测试

访问 https://www.ssllabs.com/ssltest/

测试结果评级:

  • A+:最佳
  • A:安全
  • B:可接受
  • C 及以下:需要修复

命令行测试

# 检查证书信息
openssl x509 -in fullchain.pem -text -noout

# 检查过期时间
openssl x509 -in fullchain.pem -noout -dates

总结

为 OpenClaw 配置 HTTPS 是保障安全访问的关键步骤。通过腾讯云获取免费证书,配合 Nginx 反向代理配置,可以轻松实现安全访问。

建议启用证书自动续期,避免证书过期导致服务不可用。配置完成后,使用 SSL Labs 进行全面检测,确保安全配置达到 A 级以上。

如果使用腾讯云轻量服务器,官方也提供了一键部署 HTTPS 的方案,更加便捷。