SSL证书申请及自动续期(acme.sh 三种部署方式)
官方文档:https://github.com/acmesh-official/acme.sh
一、安装
curl https://get.acme.sh | sh -s email=my@example.com
或者
wget -O - https://get.acme.sh | sh -s email=my@example.com
二、申请证书及续期
· 方式一:通过云服务商AK/SK方式,比如阿里云
阿里云AK/SK申请链接: https://ram.console.aliyun.com/users
export Ali_Key="gkslhgdsndgijsambdkuhsaodngkjnsbdf"
export Ali_Secret="kopaeuigjshdjyfoansjghkajsybnikau"
#申请证书
./acme.sh --issue --dns dns_ali -d example.com -d www.example.com
· 方式二:通过dns修改TXT记录方式,一定要根据终端提示更改DNS的TXT记录值,再申请
# 通过dns申请证书
acme.sh --issue --dns -d example.com -d www.example.com --yes-I-know-dns-manual-mode-enough-go-ahead-please
# 按控制台输出变更域名对应的TXT值后执行下面命令
acme.sh --renew -d example.com -d www.example.com --yes-I-know-dns-manual-mode-enough-go-ahead-please
· 方式三:通过网站运行目录,直接部署,比如 宝塔的Nginx
acme.sh --issue -d example.com --webroot /www/wwwroot/example.com/
acme.sh --install-cert -d example.com --key-file /www/server/panel/vhost/cert/example.com/privkey.pem --fullchain-file /www/server/panel/vhost/cert/example.com/fullchain.pem --reloadcmd "/etc/init.d/nginx reload"
三、自动续期
其实在安装acme.sh后系统会自己加一个定时任务,可以自己查看,也可以按需自己修改
1 0 * * * root /root/.acme.sh/acme.sh --cron --home /root/.acme.sh &>/var/log/acme.sh.logs
这样系统就会自动的续期证书了