免费https证书获取(Let's Encrypt)
young / / https / 阅读量

Let’s Encrypt永久免费SSL

Let’s Encrypt作为一个公共且免费SSL的项目逐渐被广大用户传播和使用,是由Mozilla、Cisco、Akamai、IdenTrust、EFF等组织人员发起,主要的目的也是为了推进网站从HTTP向HTTPS过度的进程,目前已经有越来越多的商家加入和赞助支持。

获取Let’s Encrypt免费SSL证书

系统环境 centos7.6 x64

获取证书

git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
./certbot-auto --help all
./certbot-auto certonly --standalone --email xxx@163.com -d yangxx.net -d www.yangxx.net

注意:

修改 邮箱和域名为自己的

Let’s Encrypt免费SSL证书应用

在完成Let’s Encrypt证书的生成之后,我们会在”/etc/letsencrypt/live/yangxx.net/”域名目录下有4个文件就是生成的密钥证书文件。

cert.pem – Apache服务器端证书
chain.pem – Apache根证书和中继证书
fullchain.pem – Nginx所需要ssl_certificate文件
privkey.pem – 安全证书KEY文件

如果我们使用的Nginx环境,那就需要用到fullchain.pem和privkey.pem两个证书文件,

nginx中配置

ssl_certificate /etc/letsencrypt/live/www.yangxx.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.yangxx.net/privkey.pem;

Let’s Encrypt免费SSL证书有效期问题

Let’s Encrypt证书是有效期90天的,需要我们自己手工更新续期才可以。下面通过脚本定期执行,到期前5天自动续期

脚本内容

#!/bin/bash
domain="https://xxx.net"
#获取证书的有效时间
time=$(curl --insecure -v $domain 2>&1  |grep 'expire date:'|awk -F'date:' '{print $2}')
#有效时间生成时间戳
time1=$(date +%s -d "$time")
#当前时间生成时间戳
time2=$(date +%s)
#当前时间减去有效时间,获得将要过期的天数
time3=$(((time1-time2)/(60*60*24)))

if [ $time3 -le 5 ]; then
    echo "`date` There are $time3 days to expire, now update..."
    /usr/bin/certbot renew
    systemctl restart nginx
else 
    echo "`date` There are $time3 days to expire"
fi

定时任务中加入

0 10 * * * /root/ssl/renew-cert.sh >/root/ssl/crontab.log 2>&1

更新日志:

今天准备给新博客地址配置https发现报错

Skipping bootstrap because certbot-auto is deprecated on this system.
Your system is not supported by certbot-auto anymore.
Certbot cannot be installed.
Please visit https://certbot.eff.org/ to check for other alternatives.

通过百度发现:

certbot-auto不再支持所有的操作系统!根据作者的说法,certbot团队认为维护certbot-auto在几乎所有流行的UNIX系统以及各种环境上的正常运行是一项繁重的工作,加之certbot-auto是基于python 2编写的,而python 2即将寿终正寝,将certbot-auto迁移至python 3需要大量工作,这非常困难,因此团队决定放弃certbot-auto的维护。

下面是最新方法2022-0809

yum install epel-release -y
yum install certbot -y

获取证书

# 生成证书。
certbot certonly  --email xxx@mail.com -d a.do.com -d b.do.com
# 更新证书。
certbot renew
支付宝捐赠
请使用支付宝扫一扫进行捐赠
微信捐赠
请使用微信扫一扫进行赞赏
有 0 篇文章