let's encrypt介绍
Let’s Encrypt is a free, automated, and open Certificate Authority.
acme.sh介绍
acme.sh是一个用来快速申请let's encrypt证书的脚本;
安装acme.sh
curl https://get.acme.sh | sh
source ~/.bashrc 或者 source ~/.zshrc #取决于你使用的shell
配置DNS API环境
export CF_Key="540f252b54355abc4b2705fad2c64bc7103f4"
export CF_Email="xxxxxx@gmail.com"
生成证书
acme.sh --issue --dns dns_cf -d loofahsf.com -d \*.loofahsf.com #注意*号需要转义
安装证书
acme.sh --install-cert -d loofahsf.com \
--key-file "/etc/nginx/ssl/*.loofahsf.com.key" \
--fullchain-file "/etc/nginx/ssl/*.loofahsf.com.crt" \
--reloadcmd "service nginx force-reload"
nginx配置
server {
listen 80;
server_name www.loofahsf.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name www.loofahsf.com;
ssl_certificate /etc/nginx/ssl/*.loofahsf.com.crt;
ssl_certificate_key /etc/nginx/ssl/*.loofahsf.com.key;
location / {
root /home/workspace/www;
index index.html;
}
}
开启自动续期
acme.sh --install-cronjob
[Tue Sep 11 23:22:30 EDT 2018] Installing cron job
31 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null