Contents
  1. 1. 使用Cerbot自动化申请lets-encrypt证书
  2. 2. 安装
  3. 3. 准备工作
    1. 3.1. 域名解析
    2. 3.2. nginx绑定
  4. 4. 使用
  5. 5. 续期

使用Cerbot自动化申请lets-encrypt证书

这里介绍的是ubuntu + Nginx环境,完全自动化部署,包括nginx配置也自动帮你配置好,https就是这么简单

安装

第一次使用Cerbot需要先安装

下面的命令都需要root权限,如果不是root用户,需要加上sudo

1
2
3
4
5
apt update
apt install software-properties-common
add-apt-repository ppa:certbot/certbot
apt update
apt install python-certbot-nginx

准备工作

域名解析

因为需要验证服务器和域名,所以要把需要申请证书的域名解析到当前操作服务器,不能使用CDN,如果正在用CDN需要先暂停并把域名直接解析到服务器上。

nginx绑定

确保你的域名现在是可以访问的,已经在监听80端口中,这样才能实现自动添加443端口配置

使用

就一个命令

1
certbot --nginx

会展示目前nginx正在启用的域名

1
certbot --nginx
1
2
3
4
Which names would you like to activate HTTPS for?
-------------------------------------------------------------------------------
1: lmlq.com
2: www.lmlq.com

这时候可以输入数字 选择要添加https的站

如果不输入则将所有列出的域名添加https

输入回车后开始验证域名解析

1
2
3
4
5
6
7
8
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

选择2 http重定向到https

选择1 http和https并存

从SEO方面考虑 推荐选2

输入回车后开始配置

完成

续期

手动续期:

1
certbot renew --dry-run

设置定时任务:

1
crontab -e

如果第一次使用 需要输入1-4选择编辑器

添加一行

1
2
15 3 9 * * /usr/bin/certbot renew --dry-run > /dev/null
#15分3时9日

每月的9号执行一次,可以自行修改

查看定时任务:

1
crontab -l

关于其他的环境的自动化部署可以参考 certbot官网

Contents
  1. 1. 使用Cerbot自动化申请lets-encrypt证书
  2. 2. 安装
  3. 3. 准备工作
    1. 3.1. 域名解析
    2. 3.2. nginx绑定
  4. 4. 使用
  5. 5. 续期