Let's Encrypt 大家都应该不陌生,具体生成方法和配置网上介绍较多,知道的同学应该不陌生,不知道的同学可能也用不到,这里不再做科普,本文主要说明,在大家使用类似:
certbot certonly --email example@example.com --agree-tos --no-eff-email --webroot -w /path/website -d www.example.com
- example@example.com和www.example.com分别替换为你的邮箱和域名
- /path/website 替换为你的web服务的路径
命令的时候,总是报验证错误的情况下,提供一个新的思路,帮助大家解决问题。
Let's Encrypt 的运作方式,大家可以参考:
建议大家抽时间看下,如果看不懂也没有关系,概言之就是:
Let’s Encrypt CA 会在example.com
站点的指定路径上创建了一个文件,CA 尝试从 Web 服务器下载该文件,并验证example.com
上一次性数字签名。如果 一次性数字签名有效,并且验证也成功完成,那么由公钥代表的证书管理软件将被授权对 example.com
进行证书管理。
在实际操作过程中,就是由于各种原因导致无法进行验证数字签名导致证书申请失败。
下面我们来进行证书申请:
首先我们使用向导模式进行配置:
./letsencrypt-auto certonly
./letsencrypt-auto has insecure permissions!
To learn how to fix them, visit https://community.letsencrypt.org/t/certbot-auto-deployment-best-practices/91979/
Saving debug log to /var/log/letsencrypt/letsencrypt.log
How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Spin up a temporary webserver (standalone)
2: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - -
在这里,我看到有2个选项,其中第二项就是我们常用的,和以下命令的效果相同:
certbot certonly --email example@example.com --agree-tos --no-eff-email --webroot -w /path/website -d www.example.com
在这里我们使用第一项:运行独立的 web server 来验证:
输入我们需要生成SSL证书的域名。
Plugins selected: Authenticator standalone, Installer None
Please enter in your domain name(s) (comma and/or space separated) (Enter 'c'
to cancel): www.example.com
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.example.com
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/www.example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/www.example.com/privkey.pem
Your cert will expire on 2020-06-22. To obtain a new or tweaked
version of this certificate in the future, simply run
letsencrypt-auto again. To non-interactively renew *all* of your
certificates, run "letsencrypt-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
如上,证书文件已经生成。保存在:/etc/letsencrypt/live目录下以域名命名的子目录下。
我们进入到此目录下,有以下文件:
└── www.example.com
├── cert.pem -> ../../archive/www.example.com/cert1.pem
├── chain.pem -> ../../archive/www.example.com/chain1.pem
├── fullchain.pem -> ../../archive/www.example.com/fullchain1.pem
├── privkey.pem -> ../../archive/www.example.com/privkey1.pem
└── README
各个文件含义如下:
cert.pem: 我们的域名证书
chain.pem: Let’s Encrypt证书链
fullchain.pem: cert.pem加上chain.pem
privkey.pem: 证书的专有密钥
至此,Let’s Encrypt的证书,已经生成完毕,部署到我们的Nginx或者Tomcat等WEB容器,就可以薅Let’s Encrypt的羊毛了。
最后有几点备注下:
1、版本
./certbot-auto --version
Requesting to rerun ./certbot-auto with root privileges...
./certbot-auto has insecure permissions!
To learn how to fix them, visit https://community.letsencrypt.org/t/certbot-auto-deployment-best-practices/91979/
certbot 1.3.0
2、权限
certbot-auto需要使用root权限,需要su或者root用户执行操作。