在没有自动化执行之前,我都是用的 utool 中的域名插件,手动生成泛域名证书,然后拷贝到 WAF 中的。

最近想要把这件事自动化一下,看到了一个 github 帖子【推荐】纯脚本解决雷池 WAF 自动续签问题 #987 ↗
该帖子发布较早,现在已经无法正确执行。
docker run --rm -it -v "/data/acme":/acme.sh neilpang/acme.sh --issue --dns dns_tencent -d *.987654321.xyz -d 987654321.xyz --yes-I-know-dns-manual-mode-enough-go-ahead-please
会报错:
[Tue Aug 25 07:35:45 UTC 2026] Using CA: https://acme.zerossl.com/v2/DV90
[Tue Aug 25 07:35:45 UTC 2026] No EAB credentials found for ZeroSSL, let's obtain them
[Tue Aug 25 07:35:45 UTC 2026] acme.sh is using ZeroSSL as default CA now.
[Tue Aug 25 07:35:45 UTC 2026] Please update your account with an email address first.
[Tue Aug 25 07:35:45 UTC 2026] acme.sh --register-account -m my@example.com
[Tue Aug 25 07:35:45 UTC 2026] See: https://github.com/acmesh-official/acme.sh/wiki/ZeroSSL.com-CA
[Tue Aug 25 07:35:45 UTC 2026] Please add '--debug' or '--log' to see more information.
[Tue Aug 25 07:35:45 UTC 2026] See: https://github.com/acmesh-official/acme.sh/wiki/How-to-debug-acme.sh
意思是说必须要注册一下才能使用。
所以脚本需要添加:--register-account -m my@example.com 增加这个以后会自动拿着这个邮箱注册。
我也用的是腾讯云的域名管理,然后按照要求把SAVED_Tencent_SecretId 和 SAVED_Tencent_SecretKey 写入到 account.conf 文件。
再次执行修改后的脚本:
docker run --rm -it -v "/data/acme":/acme.sh neilpang/acme.sh --register-account -m my@example.com --issue --dns dns_tencent -d *.987654321.xyz -d 987654321.xyz --yes-I-know-dns-manual-mode-enough-go-ahead-please
没有问题以后,那么就可以修改最终的renew.sh。
考虑修改:
- 建立脚本目录:mkdir /data/acme/scripts,比如我修改到了 /opt/acme/scripts;
- 建立证书归档目录:mkdir /data/acme/archived/,比如我修改为了 /opt/acme/archived/;
- WAF 证书 ID, 雷池 WAF 域名证书的 ID;
- DOMAIN, 需要生成证书的域名;
- newfile 和 oldfile 的路径;
如下是原始脚本:
#!/bin/bash
#auto renew ssl for safeline waf
#by dominicx
#cert id in safeline for this ssl
CERTID=2
DOMAIN="987654321.xyz"
ARCHIVEDDIR="/data/acme/archived/"
#step 1 renew ssl cert
docker run --rm -it -v "/data/acme":/acme.sh neilpang/acme.sh --issue --dns dns_tencent -d "*.$DOMAIN" -d "$DOMAIN"
newfile="/data/acme/*.$DOMAIN\_ecc/*.$DOMAIN.cer"
oldfile="/data/safeline/resources/nginx/certs/cert_$CERTID.crt"
newkey="/data/acme/*.$DOMAIN\_ecc/*.$DOMAIN.key"
oldkey="/data/safeline/resources/nginx/certs/cert_$CERTID.key"
if [ ! -e $newfile ] || [ ! -e $newkey ] ; then
echo "至少有一个文件不存在,请检查文件路径。"
echo $newfile
echo $newkey
exit 1
fi
newfile_ts=$(stat -c %Y $newfile)
oldfile_ts=$(stat -c %Y $oldfile)
if [ $[$newfile_ts - $oldfile_ts] -ge 300 ]; then #5 minutes
echo "Move old SSL cert files to $ARCHIVEDDIR ."
mv $oldfile $ARCHIVEDDIR
mv $oldkey $ARCHIVEDDIR
echo "Copy new SSL cert files."
cp $newfile $oldfile
cp $newkey $oldkey
keystr="$(<$newkey)"
certstr="$(<$newfile)"
sql="update mgt_ssl_cert set updated_at=to_timestamp($newfile_ts),valid_before=CAST(concat(to_timestamp($newfile_ts+90*24*3600)::date+1,' 07:59:59+08') AS TIMESTAMPTZ ),cert_content='$certstr',key_content='$keystr' where id=$CERTID;"
#update safeline pg
docker exec -it safeline-pg psql -U safeline-ce safeline-ce -c "$sql"
#nginx reload ssl cert
docker exec -it safeline-tengine nginx -s reload
echo "updating site $CERTID SSL cert file Done."
fi
最后增加个系统定时任务,每个月的 1 号和 15 号 凌晨 1:15 执行一次。
15 1 1,15 * * /opt/acme/scripts/renew.sh > /opt/acme/logs/update.log 2>&1 &

扫码分享
文章标题:脚本解决雷池 WAF 的域名证书自动续签
侵权提示:部分信息可能来源于网络。如发现有侵权,请随时联系删除!










