Let’s Encrypt是很火的一个免费SSL证书发行项目,自动化发行证书,证书有90天的有效期。而且支持多域名使用同一个证书,这很方便。
安装方法:
如果是CentOS 6、7,先执行:yum install -y epel-release
1 | wget https://dl.eff.org/certbot-auto --no-check-certificate |
单域名生成证书:
1 | ./certbot-auto certonly --email youemail@gmail.com --agree-tos --no-eff-email --webroot -w /home/wwwroot/a.com -d a.com |
多域名单目录生成单证书:(即一个网站多个域名使用同一个证书)
1 | ./certbot-auto certonly --email youemail@gmail.com --agree-tos --no-eff-email --webroot -w /home/wwwroot/a.com -d a.com -d b.com -d c.com |
多域名多目录生成一个证书:(即一次生成多个域名的一个证书)
1 | ./certbot-auto certonly --email youemail@gmail.com --agree-tos --no-eff-email --webroot -w /home/wwwroot/a.com -d a.com -d www.a.com -w /home/wwwroot/lnmp.org -d www.lnmp.org -d lnmp.org |
跑完上面命令,如果成功的话,会出现:
1 | IMPORTANT NOTES: |
生成的证书会存在:/etc/letsencrypt/live/a.com/ 目录下。
改完配置文件切记重启或reload nginx。
证书续期
cerrbot的续期比原来的更加简单,因为证书只有90天,所以建议使用crontab进行自动续期:
crontab 里加上如下规则:0 3 */5 * * /root/certbot-auto renew --disable-hook-validation --renew-hook "/etc/init.d/nginx reload"
这样每5天就会执行一次所有域名的续期操作。当然时间也可以自行进行调整,建议别太频繁,因为他们都有请求次数的限制,如果需要强制更新可以在前面命令上加上 --force-renew 参数。
注意事项:
1、因为默认LNMP的虚拟主机里是禁止 . 开头的隐藏文件及目录的,所以访问http://a.com/.well-known/acme-challenge/**** 这个链接的话返回403错误,所以必须要将对应虚拟主机配置文件里的
1 | location ~ /\. |
这段配置删掉或注释掉或在这段配置前面加上
1 | location ~ /.well-known { |
以上配置代码,然后重启nginx。
或者直接去下面这个网址申请,一样的。
https://www.sslforfree.com/
参考资料:
https://www.vpser.net/build/letsencrypt-certbot.html
https://diamondfsd.com/article/e221b455-b0e7-40b7-a6c7-9bb7e3e35657
https://certbot.eff.org/#centos6-nginx