本文参考Certbot User Guide,以longlive.su
域名为例,示范如何手动或通过宝塔面板自动为域名申请免费的泛域名(通配符)SSL证书。
手动申请
本章需要用到Linux命令行环境,推荐在Windows WSL
中操作。
0. 准备工作
安装Certbot
sudo apt install certbot
1. 申请证书
申请证书的命令格式为:certbot certonly -d "域名" --manual --preferred-challenges "Challenge Types 验证方式" --server https://acme-v02.api.letsencrypt.org/directory
Challenge Types可用的验证方式可以参考:https://letsencrypt.org/docs/challenge-types/
其中常用的验证方式包括HTTP-01
和DNS-01
,HTTP-01
既是通过文件方式验证,而DNS-01
则是通过DNS记录的方式验证。
如以DNS方式为longlive.su
申请证书:
certbot certonly -d "*.longlive.su, longlive.su" --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
注意这里要同时写上*.longlive.su
和longlive.su
,因为*.longlive.su
并不包括longlive.su
本身,所以我们需要在申请泛域名证书的同时包括一级域名本身。
接下来同意记录IP地址后,会收到如下的提示:
Please deploy a DNS TXT record under the name _acme-challenge.longlive.su with the following value: CHjNzDuTtxnzk96n-vwGnJJcTEnulQzKaDarX532oyI Before continuing, verify the record is deployed.
按照要求在域名下增加相应DNS记录,完成后等待一段时间(一般的域名增加后立即就能生效了,但是.su
好像要慢一些)再按Enter
继续。
如果正确设置了DNS记录,会提示通过验证,成功生成了证书:
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/longlive.su/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/longlive.su/privkey.pem Your cert will expire on 2021-10-17. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew all of your certificates, run "certbot renew"
可以看到证书保存的具体位置,之后将证书部署到服务器上即可。
2. 效果

注意申请证书时域名的顺序会影响证书的显示效果(但并不影响正常的功能)。第一位的域名会显示在证书的“通用名称(Subject Name)”中,其余的会显示在“备用名称(Subject Alt Names)”中。
宝塔面板申请证书
宝塔面板支持为阿里云DNS(还有DnsPod等)平台绑定的域名自动申请证书,只需要是“DNS云解析”中的域名就可以了,不需要是阿里云注册的域名。
0. 申请AccessKey
从阿里云右上角的用户头像处进入“AccessKey”管理,创建AccessKey。


进入宝塔面板网站的SSL页面,填入刚申请的AccessKey和SecretKey。

1. 申请证书
勾选要申请的域名,一般勾选顶级域名和泛域名(通配符域名)即可。

点击“申请”按钮就可以由宝塔面板自动申请,正常的话很快就能申请成功。

以自动方式申请的证书能自动续签,有条件的话由宝塔面板自动申请证书的话更加省时省力。
《免费申请SSL泛域名证书(手动及宝塔面板)》上有1条评论
评论已关闭。