HTTPS 配置
生产环境强烈建议使用 HTTPS。Glean 本身不处理 SSL,需要使用反向代理。
方式一:Caddy(推荐)
Section titled “方式一:Caddy(推荐)”Caddy 自动获取和续期 Let’s Encrypt 证书,配置最简单。
安装 Caddy
Section titled “安装 Caddy”# Ubuntu/Debiansudo apt install caddy
# macOSbrew install caddy配置 Caddyfile
Section titled “配置 Caddyfile”创建 Caddyfile:
glean.yourdomain.com { reverse_proxy localhost:80}
admin.yourdomain.com { reverse_proxy localhost:3001}启动 Caddy
Section titled “启动 Caddy”caddy run --config CaddyfileCaddy 会自动:
- 获取 SSL 证书
- 配置 HTTPS
- 自动续期证书
方式二:Nginx + Certbot
Section titled “方式二:Nginx + Certbot”安装 Nginx 和 Certbot
Section titled “安装 Nginx 和 Certbot”# Ubuntu/Debiansudo apt install nginx certbot python3-certbot-nginx配置 Nginx
Section titled “配置 Nginx”创建 /etc/nginx/sites-available/glean:
# Web 应用server { listen 80; server_name glean.yourdomain.com;
location / { proxy_pass http://localhost:80; 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; }}
# 管理后台server { listen 80; server_name admin.yourdomain.com;
location / { proxy_pass http://localhost:3001; 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; }}sudo ln -s /etc/nginx/sites-available/glean /etc/nginx/sites-enabled/sudo nginx -tsudo systemctl reload nginx获取 SSL 证书
Section titled “获取 SSL 证书”sudo certbot --nginx -d glean.yourdomain.com -d admin.yourdomain.comCertbot 会自动:
- 获取证书
- 配置 Nginx
- 设置自动续期
更新 CORS 配置
Section titled “更新 CORS 配置”配置 HTTPS 后,需要更新 CORS 设置:
# 编辑 .env 文件CORS_ORIGINS='["https://glean.yourdomain.com", "https://admin.yourdomain.com"]'重启后端服务:
docker compose restart backend使用自签名证书
Section titled “使用自签名证书”仅用于测试环境,不推荐生产使用。
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ -keyout /etc/ssl/private/glean.key \ -out /etc/ssl/certs/glean.crt \ -subj "/CN=glean.local"Nginx 配置
Section titled “Nginx 配置”server { listen 443 ssl; server_name glean.local;
ssl_certificate /etc/ssl/certs/glean.crt; ssl_certificate_key /etc/ssl/private/glean.key;
location / { proxy_pass http://localhost:80; 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; }}安全最佳实践
Section titled “安全最佳实践”SSL 配置优化
Section titled “SSL 配置优化”# 在 server 块中添加ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;ssl_prefer_server_ciphers off;
# HSTSadd_header Strict-Transport-Security "max-age=63072000" always;强制 HTTPS 重定向
Section titled “强制 HTTPS 重定向”server { listen 80; server_name glean.yourdomain.com; return 301 https://$server_name$request_uri;}检查 SSL 证书
Section titled “检查 SSL 证书”# 使用 curl 验证curl -v https://glean.yourdomain.com
# 使用 openssl 检查openssl s_client -connect glean.yourdomain.com:443使用 SSL Labs 检测 SSL 配置评分。
证书续期失败
Section titled “证书续期失败”# 手动续期sudo certbot renew
# 检查续期状态sudo certbot certificates混合内容警告
Section titled “混合内容警告”确保所有资源都通过 HTTPS 加载,检查浏览器控制台是否有混合内容警告。
反向代理后获取真实 IP
Section titled “反向代理后获取真实 IP”确保 Nginx 配置正确传递了 X-Forwarded-For 和 X-Real-IP 头。