免费泛域名SSL证书

邱秋 • 2024年08月11日 • 阅读:68 • ssl linux

如何申请免费的泛域名SSL证书

下载 acme.sh 工具

acme.sh 官方提供一个非常简单的一键安装脚本,老少皆宜。当然,安装这个工具对于是否在公网并没有任何要求,你可以选择在将要部署 SSL 证书的内网服务器中安装即可,请用非root用户全程执行命令。

# 下面的邮箱换成你的
curl  https://get.acme.sh | sh -s email=***@gmail.com

如果你的安装服务器位于中国大陆境内, 访问 github 可能会不成功. 所以安装可能会失败.

git clone https://gitee.com/chuchur/acme.sh
cd acme.sh
./acme.sh --install -m ***@gmail.com

验证域名

安装好acme.sh工具,就可以开始提交泛域名申请了,DNS验证和HTTP验证二选一

1.DNS验证

按照下面命令就可以使用 DNS 验证的方式来提交申请。结果会返回一个 TXT 记录新增的要求。

# 下面的域名换成你的
acme.sh --issue --dns -d xxx.org -d *.xxx.org --yes-I-know-dns-manual-mode-enough-go-ahead-please

不出意外你就能得到

$ Domain: '_acme-challenge.xxx.com'
$ TXT value: 'Tmc1vpZmXlK8h6HzPdzWoLdwNMgiXKdw6X77XFZE_fU'
$ Please make sure to prepend '_acme-challenge.' to your domain

接下来在你的域名解析中增加一条 TXT 记录值

_acme-challenge 是Name,  Tmc1vpZmXlK8h6HzPdzWoLdwNMgiXKdw6X77XFZE_fU 是value

2.HTTP验证

$ acme.sh --issue -d xx.com -d *.xx.com -w /home/webroot

对于通配符证书需要加 -d 域名 -d *.域名 两个参数-w 即webroot,为该 域名 通过http所访问到的本地目录上面这段过程将会在 /home/webroot 创建一个 .well-known 的文件夹,同时 Let’s Encrypt 将会通过你要注册的域名去访问那个文件来确定权限,它可能会去访问 http://xx.com/.well-known/ 这个路径,验证成功会自动清理。

!!!HTTP不支持泛域名验证

你可能还需要修改对应的nignx 配置:

server {
    listen 80;
    server_name yourdomain.com;

    location ^~ /.well-known/ {
        default_type "text/plain";
        root /path/to/your/website/root;
    }

    # 其他配置...
}

生成证书

如果验证通过之后就可以立即生成新的证书了

# xx.org 换成你的域名
acme.sh --renew -d xx.org -d *.xx.org --yes-I-know-dns-manual-mode-enough-go-ahead-please

不出意外的话就能看到

$ Your cert is in: /root/.acme.sh/xx_ecc/xx.cer
$ Your cert key is in: /root/.acme.sh/xx_ecc/xx.key
$ The intermediate CA cert is in: /root/.acme.sh/xx_ecc/ca.cer
$ And the full-chain cert is in: /root/.acme.sh/xx_ecc/fullchain.cer

一般我们在nginx 或者其他地方只需要 xx.keyfullchain.cer 就可以了.

其他

1、查看已签发证书的域名:

$ acme.sh --list

2、移除不需要再次签发证书的域名:

$ acme.sh --remove -d example.com

3、强制刷新证书

$ acme.sh --renew -d example.com --force

4、查看已安装证书信息

$ acme.sh --info -d example.com
# 会输出如下内容:
DOMAIN_CONF=/root/.acme.sh/example.com/example.com.conf
Le_Domain=example.com
Le_Alt=no
Le_Webroot=dns_ali

5、卸载

$ acme.sh --uninstall

我,秦始皇,打钱!