一、准备工作
1、我的ubuntu版本
2、安装Python 2.7.8(或更高版本).
sudo apt-get update
sudo apt-get install python3-pip
验证版本:
3、下载安装Let的加密客户端(certbot)
sudo apt install certbot
4、域名
Certbot生成Let’s Encrypt免费证书的过程中一定需要域名。Let’s Encrypt是一个公共的证书颁发机构,它提供免费的SSL证书服务,但要求用户必须拥有一个域名,并且能够通过域名验证来确认对该域名的控制权。这是为了确保证书只会被授予给实际拥有该域名的人或组织,以增强证书的安全性。所以在使用Certbot生成Let’s Encrypt证书之前,必须确保已经拥有并控制该域名。
这里我的域名是:nothingjira.nothing.tech
后续操作步骤将该域名替换成你自己的。
二、申请秘钥
1、为域名生成证书:sudo certbot certonly -d “域名” -d “*.域名” --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
sudo certbot certonly -d "nothingjira.nothing.tech" -d "*.nothingjira.nothing.tech" --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
2、在域名解析添加txt记录。
执行上面的命令后会提示你部署DNS TXT记录,如下:
Please deploy a DNS TXT record under the name:
_acme-challenge.nothingjira.nothing.tech.
with the following value:
Pst5u6gC1omx7heR0tscQS_rVYuhaxze3KR47wjb06Y
将name和value添加到txt记录:
过程中会提示查看txt记录是否成功生成,是即可下一步,全过程如下:
3、生成Key。Spring Boot需要PKCS#12格式的文件.这意味着您必须将密钥转换为PKCS#12密钥库(例如,使用OpenSSL)。
sudo openssl pkcs12 -export -in "/etc/letsencrypt/live/域名/cert.pem" -inkey "/etc/letsencrypt/live/域名/privkey.pem" -out "/etc/letsencrypt/live/域名/key.p12"
示例:
sudo openssl pkcs12 -export -in "/etc/letsencrypt/live/nothingjira.nothing.tech/cert.pem" -inkey "/etc/letsencrypt/live/nothingjira.nothing.tech/privkey.pem" -out "/etc/letsencrypt/live/nothingjira.nothing.tech/key.p12"
查看是否生成key.p12文件:
4、在SpringBoot中配置
5、在浏览器查看是否已经生效
三、在nodejs中调用接口,报错:“unable to verify the first certificate”
1、在服务器上检测证书链是否完整
GPT上查找产生无效的原因:
到这里已经猜到是缺少中间证书的原因。
2、在线工具检查链接
检查证书是否完整。
结果:
3、在Let’s Encrypt社区找答案
https://community.letsencrypt.org/t/unable-to-verify-the-first-certificate/140756
两者的区别:
4、在SpringBoot配置文件添加配置:
5、nodejs成功返回数据
附证书链原图: