使用certbot来进行Let’s Encrypt的ssl 配置

星期四, 2017-05-18 | Author: Lee | JAVA-and-J2EE, linux | 3,871 views

之前let’s encrypt 的老版本可以参考这篇文章主要配置也都相同
//www.pomelolee.com/1562.html

基于nginx配置
安装方法

如果是CentOS 6,先执行:yum install epel-release
cd /root/
wget https://dl.eff.org/certbot-auto –no-check-certificate
chmod +x ./certbot-auto
./certbot-auto -n
接下来就会自动安装所需的依赖包。

配置nginx

1
2
3
4
5
6
7
8
location ^~ /.well-known/acme-challenge/ {
   default_type "text/plain";
   root     /usr/share/nginx/html;
}
 
location = /.well-known/acme-challenge/ {
   return 404;
}

生成证书

单域名生成证书:

1
./certbot-auto certonly --email username@domain --agree-tos --webroot -w /websiteroot -d domain

多域名单目录生成单证书:

1
./certbot-auto certonly --email username@domain --agree-tos --webroot -w /websiteroot -d domain1 -d domain2

多域名多目录生成多个证书:

1
./certbot-auto certonly --email admin@vpser.net --agree-tos --webroot -w /websiteroot1 -d domain1 -d domain2 -w /websiteroot2 -d domain3 -d domain4

证书更新

进入Let’s Encrypt目录,执行./certbot-auto renew即可,建议添加Cron
执行完记得reload 下nginx配置

1、测试一下更新,这一步没有在真的更新,只是在调用 Certbot 进行测试

1
./certbot-auto renew --dry-run

如果出现类似的结果,就说明测试成功了(总之有 Congratulations 的字眼)

1
2
3
4
Congratulations, all renewals succeeded. The following certs have been renewed:  
   /etc/letsencrypt/live/i5a6.com/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)

2、手动更新的方法

1
./certbot-auto renew -v

3、自动更新的方法

1
./certbot-auto renew --quiet --no-self-upgrade

♦一些补充说明解释

1、certbot-auto 和 certbot

certbot-auto 和 certbot 本质上是完全一样的;不同之处在于运行 certbot-auto 会自动安装它自己所需要的一些依赖,并且自动更新客户端工具。因此在你使用 certbot-auto 情况下,只需运行在当前目录执行即可

./certbot-auto

2、certbot的两种工作方式

certbot (实际上是 certbot-auto ) 有两种方式生成证书:

standalone 方式: certbot 会自己运行一个 web server 来进行验证。如果我们自己的服务器上已经有 web server 正在运行 (比如 Nginx 或 Apache ),用 standalone 方式的话需要先关掉它,以免冲突。

webroot 方式: certbot 会利用既有的 web server,在其 web root目录下创建隐藏文件, Let’s Encrypt 服务端会通过域名来访问这些隐藏文件,以确认你的确拥有对应域名的控制权。

本文用的是 webroot 方式,也只推荐 webroot 方式,这也是前文第二步验证域名所有权在 nginx 虚拟主机配置文件中添加 location 段落内容的原因。

Tags: , ,

文章作者: Lee

本文地址: https://www.pomelolee.com/1720.html

除非注明,Pomelo Lee文章均为原创,转载请以链接形式标明本文地址

一条评论 to 使用certbot来进行Let’s Encrypt的ssl 配置

Lee
2018 年 05 月 10 日

cd /usr/local/webserver/letssl
./certbot-auto renew –force-renew -v ##强制更新

Leave a comment

Search

文章分类

Links

Meta