申请Let's Encrypt泛域名免费证书(无需域名80端口)

版权声明:本文为博主原创文章,转载请附上博文链接,谢谢! https://blog.csdn.net/qq_30062125/article/details/84937786

1、前言

最近有个外网域名需要申请证书,准备用Let's Encrypt证书,毕竟免费吗。可惜脚本中会验证域名的80端口,很不幸80端口因为某些原因无法开放,后来无意中发现一个方法,结合Neilpang/acme.sh和泛域名,这里记录下。

Neilpang/acme.sh参考:https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E

2、步骤

2.1 执行安装脚本

curl https://get.acme.sh | sh 或者

wget -O - https://get.acme.sh | sh 或者

curl https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh | INSTALLONLINE=1 sh 或者

wget -O - https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh | INSTALLONLINE=1 sh

脚本安装在~/.acme.sh目录下

2.2 申请泛域名证书

./acme.sh --issue -d *.qwcsp.cf -d *.qwcsp.tk --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please

2.3 域名解析服务器添加域名的TXT解析

红方框中就是需要的信息。

2.4 获取Let's Encrypt泛域名证书

2.4.1 查看TXT信息步骤:

2.4.1.1 安装nslookup

yum install -y bind-utils

2.4.1.2 查看信息

nslookup -q=TXT baidu.com

2.4.2 DSN解析生效后,运行命令

./acme.sh --renew -d *.qwcsp.cf -d *.qwcsp.tk --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please

2.5 证书说明

在~/.acme.sh目录下会产生“*.域名”的文件夹,里面就是证书,fullchain.cer是完整的证书,具体的证书区分见

证书格式说明 openssl生成自签证书 中的证书类型说明。

[root@node190 .acme.sh]# tree *.qwcsp.cf

*.qwcsp.cf

├── ca.cer

├── fullchain.cer

├── *.qwcsp.cf.cer 证书

├── *.qwcsp.cf.conf

├── *.qwcsp.cf.csr 证书申请文件

├── *.qwcsp.cf.csr.conf

├── *.qwcsp.cf.key 私钥

└── qwcsp.cf.pem

附:

pem格式生成命令:

cat fullchain.cer \*.qwcsp.cf.key | tee qwcsp.cf.pem

强制更新命令:

./acme.sh --force --renew -d *.qwcsp.cf -d *.qwcsp.tk --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please

2.6 生成tomcat的证书

# 导出.p12格式的证书

/root/.acme.sh/*.qwcsp.cf

[root@node190 *.qwcsp.cf]# openssl pkcs12 -export -in fullchain.cer -inkey *.qwcsp.cf.key -out *.qwcsp.cf.p12 -name tomcat_letsencrypt

Enter Export Password:

Verifying - Enter Export Password:

# 再将证书由.p12格式转换成.jks格式

$ keytool -importkeystore -deststorepass '123456' -destkeypass '123456' -destkeystore *.qwcsp.cf.jks -srckeystore *.qwcsp.cf.p12 -srcstoretype PKCS12 -srcstorepass '123456' -alias tomcat_letsencrypt

# 修改tomcat配置

修改 %tomcat%/conf/server.xml 文件,添加 keystoreFile 和 keystorePass 两行配置。其中,keystoreFile 指向 jks 证书文件,而 keystorePass 则为证书的密钥。修改后的关键配置如下:

<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true"

maxThreads="150" scheme="https" secure="true"

clientAuth="false" sslProtocol="TLS"

keystoreFile="/home/test/*.qwcsp.cf.jks"

keystorePass="123456"

/>

猜你喜欢

转载自blog.csdn.net/qq_30062125/article/details/84937786