#!/bin/bash # Let's Encrypt 证书初始化脚本 # 用法: ./init-cert.sh <域名> [邮箱] set -e DOMAIN=$1 EMAIL=${2:-"admin@stonelan.cn"} if [ -z "$DOMAIN" ]; then echo "用法: $0 <域名> [邮箱]" echo "示例: $0 fastgpt.stonelan.cn admin@example.com" exit 1 fi echo "开始为域名 $DOMAIN 申请证书..." # 确保 certbot 容器运行 docker compose up -d # 等待容器启动 sleep 5 # 申请证书(使用 webroot 验证方式) docker compose exec certbot certbot certonly \ --webroot \ --webroot-path=/var/www/certbot \ --email "$EMAIL" \ --agree-tos \ --no-eff-email \ -d "$DOMAIN" \ --force-renewal echo "证书申请完成!" echo "证书路径: /etc/letsencrypt/live/$DOMAIN/"