上次写过一篇 Nginx Tomcat 实现网站全站https 基于免费的SSL证书Let's Encrypt 免费SSL证书实现全站HTTPS ,大致内容是指定域名的SSL证书,虽然可以多个域名,但是一旦决定就无法更改,搞得很难扩展。
例如 我有3个域名要https分别是主域名 tczmh.club 子域名 www.tczmh.club bz.tczmh.club
如果我又要开新子域名 例如download.tczmh.club 或者 cdn1.tczmh.club 就需要从头再来一次
这次发现另一个工具,可以直接通配符 * 代替所有二级域名,一次支持所有二级域名。就是以后任意二级域名都可以免重新注册直接使用了!~
方法是借鉴了简书 csdn等大神的教程,我就重点说说有哪些巨坑吧
- # 第一步没什么花头的 找个位置 下载赋权
- # 下载
- wget https://dl.eff.org/certbot-auto
- # 设为可执行权限
- chmod u+x certbot-auto
第一个巨坑来了 *.tczmh.club 是不包括tczmh.club的,也就是说会造成二级域名安全通过,主域名被卡住的情况,所以要2个-d 带主域名和通配符的二级域名
- # -d后面的域名替换成你自己的
- ./certbot-auto certonly -d "tczmh.club" -d "*.tczmh.com" --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
接下来没什么花头,第一个是输入邮箱,第二三个都同意一下,关键是 第四个 类似下面这段话
- -------------------------------------------------------------------------------
- Please deploy a DNS TXT record under the name
- _acme-challenge.tczmh.club with the following value:
- 6XnGyee8W48QfRl61m_18aRs8rfvn4T8kKzQil0IYw4
- Before continuing, verify the record is deployed.
- -------------------------------------------------------------------------------
- Press Enter to Continue
到这一步千万别直接回车。。。这段话是让你在域名解析里加个dns解析
需要去你的域名提供商那边添加一条dns解析,用来证明这个域名是你自己的。
主机记录 : _acme-challenge
记录值 : 6XnGyee8W48QfRl61m_18aRs8rfvn4T8kKzQil0IYw4
其余默认即可
这里的巨坑就是很容易炸,千万不要很急就刚配完DNS就回来点回车,DNS解析这东西有时效性
再就是如果前面一次炸了,重新来,建议配完暂停一下,再启动一下,再等1分钟
我试了发现这样的成功率最高,否则取不到或者取到上一次的缓存的可能性非常大!
对了忘说了,这里错了没关系的,可以直接重新执行上一步的命令来重试,可以一直试到成功为止
错误的结果
- Failed authorization procedure. tczmh.club (dns-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Incorrect TXT record "6XnGyee8W48QfRl61m_18aRs8rfvn4T8kKzQil0IYw4" found at _acme-challenge.tczmh.club
- IMPORTANT NOTES:
- - The following errors were reported by the server:
- Domain: tczmh.club
- Type: unauthorized
- Detail: Incorrect TXT record
- "6XnGyee8W48QfRl61m_18aRs8rfvn4T8kKzQil0IYw4" found at
- _acme-challenge.tczmh.club
- To fix these errors, please make sure that your domain name was
- entered correctly and the DNS A/AAAA record(s) for that domain
- contain(s) the right IP address.
- - Your account credentials have been saved in your Certbot
- configuration directory at /etc/letsencrypt. You should make a
- secure backup of this folder now. This configuration directory will
- also contain certificates and private keys obtained by Certbot so
- making regular backups of this folder is ideal.
- - We were unable to subscribe you the EFF mailing list because your
- e-mail address appears to be invalid. You can try again later by
- visiting https://act.eff.org.
- [root@VM_0_14_centos ssltools]# ./certbot-auto certonly -d *.tczmh.club -d tczmh.club --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
- Saving debug log to /var/log/letsencrypt/letsencrypt.log
- Plugins selected: Authenticator manual, Installer None
- Obtaining a new certificate
- Performing the following challenges:
- dns-01 challenge for tczmh.club
- dns-01 challenge for tczmh.club
正确的结果
- Press Enter to Continue
- Waiting for verification...
- Cleaning up challenges
- IMPORTANT NOTES:
- - Congratulations! Your certificate and chain have been saved at:
- /etc/letsencrypt/live/tczmh.club/fullchain.pem
- Your key file has been saved at:
- /etc/letsencrypt/live/tczmh.club/privkey.pem
- Your cert will expire on 2018-12-07. To obtain a new or tweaked
- version of this certificate in the future, simply run certbot-auto
- again. To non-interactively renew *all* of your certificates, run
- "certbot-auto renew"
- - If you like Certbot, please consider supporting our work by:
- Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
- Donating to EFF: https://eff.org/donate-le
然后如何把密码用到nginx和tomcat的方法在前面的博客里有
Nginx加Tomcat实现网站免费全站https 基于Let's Encrypt
续约的方法
- # 续约命令 (可能会和nginx冲突要先停nginx)
- ./certbot-auto renew
可以使用crontab -e 来定期自动续约