前言
HTTPS 已成为网站标配,但证书过期导致的网站宕机仍频繁发生。本文介绍全自动证书管理方案。
一、选择 acme.sh 的理由
- 纯 Shell 脚本,依赖极少
- 支持所有主流 DNS API
- 自动续期,零维护
二、安装与配置
curl https://get.acme.sh | sh
三、Cloudflare DNS 验证
export CF_Token="your_token"
./acme.sh --issue --dns dns_cf -d example.com -d *.example.com
四、阿里云 DNS 验证
export Ali_Key="your_key"
export Ali_Secret="your_secret"
./acme.sh --issue --dns dns_ali -d example.com
五、安装证书
./acme.sh --install-cert -d example.com \
--key-file /etc/ssl/private/example.com.key \
--fullchain-file /etc/ssl/certs/example.com.crt \
--reloadcmd "systemctl reload nginx"
六、Nginx 配置
server {
listen 443 ssl http2;
ssl_certificate /etc/ssl/certs/example.com.crt;
ssl_certificate_key /etc/ssl/private/example.com.key;
}
七、自动续期
acme.sh 会自动创建 cron 任务,每天检查,到期前 30 天自动续期,无需手动干预。
总结
使用 acme.sh + DNS 验证,一次配置永久省心,彻底告别证书过期问题。