在前往活动页了解产品、购买轻量服务器(参考腾讯云 OpenClaw 特别优惠)、部署 OpenClaw 后,如果想要通过域名安全访问,配置 SSL 证书是必经之路。本文将详细介绍如何为 OpenClaw 配置 HTTPS。
腾讯云提供免费 SSL 证书:
高安全性场景可选择付费证书:
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.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 版本支持直接配置:
# 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
vim ~/openclaw/nginx.conf
# 粘贴上面的配置
cd ~/openclaw
docker-compose up -d
# 检查 Nginx 配置
docker-compose exec nginx nginx -t
# 查看运行状态
docker-compose ps
# 测试访问
curl -I https://your-domain.com
# 检查证书信息
openssl s_client -connect your-domain.com:443 -servername your-domain.com
免费证书有效期 90 天,需要定期续期。
# 安装 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"
腾讯云付费证书支持自动续期,配置后无需手动操作。
确保配置了 WebSocket 代理:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
chmod 600 ~/openclaw/ssl/private.key
chmod 644 ~/openclaw/ssl/fullchain.pem
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
访问 https://www.ssllabs.com/ssltest/
测试结果评级:
# 检查证书信息
openssl x509 -in fullchain.pem -text -noout
# 检查过期时间
openssl x509 -in fullchain.pem -noout -dates
为 OpenClaw 配置 HTTPS 是保障安全访问的关键步骤。通过腾讯云获取免费证书,配合 Nginx 反向代理配置,可以轻松实现安全访问。
建议启用证书自动续期,避免证书过期导致服务不可用。配置完成后,使用 SSL Labs 进行全面检测,确保安全配置达到 A 级以上。
如果使用腾讯云轻量服务器,官方也提供了一键部署 HTTPS 的方案,更加便捷。