有时候需要使用SSL证书而不需要安装nginx等服务时,可以使用下面的方法手动申请Let’sEncrypt免费SSL证书
certbot
获取git clone https://github.com/letsencrypt/letsencrypt
申请证书
首先将域名正确解析到要使用的服务器IP上,然后执行:
./letsencrypt/letsencrypt-auto certonly --standalone --email email@example.com -d domainname.xyz
注意将email@example.com和domainname.xyz正确替换为自己的邮箱和域名,该邮箱用于接受过期提醒邮件。快到期时重新执行上述命令即可完成更新。
##申请到证书的路径
证书文件路径:/etc/letsencrypt/live/domainname/fullchain.pem
密钥文件路径:/etc/letsencrypt/live/domainname/privkey.pem
##更新证书
./letsencrypt/letsencrypt-auto renew
2021年四月更新
使用条件参考官方说明
ubuntu下按如下步骤操作:
apt install snapd
snap install core
snap refresh core
snap install --classic certbot
然后关闭nginx等开放80端口nginx -s quit
的站点,后面的步骤同上
certbot certonly --standalone --email astralhope@gmail.com -d liuyu.39hope.icu
运行certbot renew
更新证书
lnmp下:
/usr/local/nginx/sbin/nginx -s stop
2023年三月更新
无80端口下申请证书
certbot certonly --manual --preferred-challenge dns --email astralhope@gmail.com -d liuyu.39hope.icu
过程中需要将提示内容填入DNS解析
Please deploy a DNS TXT record under the name:
_acme-challenge.liuyu.39hope.icu.
with the following value:
一串值
Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.ab.n5105.39hope.com.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.
在DNS解析处添加TXT类型解析,Name填入_acme-challenge.liuyu.39hope
,content填入下面的一串值后继续即可申请成功。
certbot 常用命令:
certbot certificates
就可以看到当前机器所有域名的证书情况,包括域名、 到期日、证书路径、私钥路径四条信息。
续费所有的域名
certbot renew
删除过期不用的域名
certbot delete --cert-name example.com