HTTPS之acme.sh申请证书 您所在的位置:网站首页 腾讯云内网dns HTTPS之acme.sh申请证书

HTTPS之acme.sh申请证书

2023-07-23 13:24| 来源: 网络整理| 查看: 265

1.关于let's encrypt和acme.sh的简介1.1 let's encrypt

Let's Encrypt是一个于2015年三季度推出的数字证书认证机构,旨在以自动化流程消除手动创建和安装证书的复杂流程,并推广使万维网服务器的加密连接无所不在,为安全网站提供免费的SSL/TLS证书。 Let's Encrypt由互联网安全研究小组(缩写ISRG)提供服务。主要赞助商包括电子前哨基金会、Mozilla基金会、Akamai以及思科。2015年4月9日,ISRG与Linux基金会宣布合作。 用以实现新的数字证书认证机构的协议被称为自动证书管理环境(ACME)。GitHub上有这一规范的草案,且提案的一个版本已作为一个Internet草案发布。 Let's Encrypt宣称这一过程将十分简单、自动化并且免费

1.2 acme.sh

简单来说acme.sh 实现了 acme 协议, 可以从 let‘s encrypt 生成免费的证书。 acme.sh 有以下特点:

一个纯粹用Shell(Unix shell)语言编写的ACME协议客户端。完整的ACME协议实施。 支持ACME v1和ACME v2 支持ACME v2通配符证书简单,功能强大且易于使用。你只需要3分钟就可以学习它。Let's Encrypt免费证书客户端最简单的shell脚本。纯粹用Shell编写,不依赖于python或官方的Let's Encrypt客户端。只需一个脚本即可自动颁发,续订和安装证书。 不需要root/sudoer访问权限。支持在Docker内使用,支持IPv62.安装acme.sh2.1 执行安装

https://github.com/Neilpang/acme.sh/wiki/dns-manual-mode 安装很简单, 一个命令:

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

脚本会根据系统不通选择不同的下载方式:

[[email protected] /opt] #wget -O - https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh | INSTALLONLINE=1 sh --2018-11-13 15:31:42-- https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh 正在解析主机 raw.githubusercontent.com... 151.101.0.133, 151.101.64.133, 151.101.128.133, ... 正在连接 raw.githubusercontent.com|151.101.0.133|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:168608 (165K) [text/plain] 正在保存至: “STDOUT” 100%[======================================================================>] 168,608 --.-K/s in 0.07s 2018-11-13 15:31:42 (2.38 MB/s) - 已写入标准输出 [168608/168608] [2018年 11月 13日 星期二 15:31:42 CST] Installing from online archive. [2018年 11月 13日 星期二 15:31:42 CST] Downloading https://github.com/Neilpang/acme.sh/archive/master.tar.gz [2018年 11月 13日 星期二 15:31:43 CST] Extracting master.tar.gz [2018年 11月 13日 星期二 15:31:43 CST] It is recommended to install socat first. [2018年 11月 13日 星期二 15:31:43 CST] We use socat for standalone server if you use standalone mode. [2018年 11月 13日 星期二 15:31:43 CST] If you don't use standalone mode, just ignore this warning. [2018年 11月 13日 星期二 15:31:43 CST] Installing to /root/.acme.sh [2018年 11月 13日 星期二 15:31:43 CST] Installed to /root/.acme.sh/acme.sh [2018年 11月 13日 星期二 15:31:43 CST] Installing alias to '/root/.bashrc' [2018年 11月 13日 星期二 15:31:43 CST] OK, Close and reopen your terminal to start using acme.sh [2018年 11月 13日 星期二 15:31:43 CST] Installing alias to '/root/.cshrc' [2018年 11月 13日 星期二 15:31:43 CST] Installing alias to '/root/.tcshrc' [2018年 11月 13日 星期二 15:31:43 CST] Installing cron job #未知信息,已禁用 :34 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null [2018年 11月 13日 星期二 15:31:43 CST] Good, bash is found, so change the shebang to use bash as preferred. [2018年 11月 13日 星期二 15:31:44 CST] OK [2018年 11月 13日 星期二 15:31:44 CST] Install success!2.2 安装后的配置

普通用户和 root 用户都可以安装使用。 安装过程进行了以下几步: 把 acme.sh 安装到你的 home 目录下:~/.acme.sh/并创建 一个 bash 的 alias, 方便你的使用:

alias acme.sh=~/.acme.sh/acme.sh echo 'alias acme.sh=~/.acme.sh/acme.sh' >>/etc/profile

安装过程中会自动为你创建 cronjob, 每天 0:00 点自动检测所有的证书, 如果快过期了, 需要更新, 则会自动更新证书。

00 00 * * * root /root/.acme.sh/acme.sh --cron --home /root/.acme.sh &>/var/log/acme.sh.logs

更高级的安装选项请参考: https://github.com/Neilpang/acme.sh/wiki/How-to-install 在该脚本的安装过程不会污染已有的系统任何功能和文件, 所有的修改都限制在安装目录中: ~/.acme.sh/

3.申请证书

acme.sh 实现了 acme 协议支持的所有验证协议. 一般有两种方式验证: http 和 dns 验证。

3.1 HTTP 方式

http 方式需要在你的网站根目录下放置一个文件, 来验证你的域名所有权,完成验证. 然后就可以生成证书了.

acme.sh --issue -d clsn.io -d *.clsn.io --webroot /www/wwwroot/clsn.io/

只需要指定域名, 并指定域名所在的网站根目录. acme.sh 会全自动的生成验证文件, 并放到网站的根目录, 然后自动完成验证. 最后会聪明的删除验证文件. 整个过程没有任何副作用. 如果你用的 apache服务器, acme.sh 还可以智能的从 apache的配置中自动完成验证, 你不需要指定网站根目录:

acme.sh --issue -d clsn.io --clsn.io

如果你用的 nginx服务器, 或者反代, acme.sh 还可以智能的从 nginx的配置中自动完成验证, 你不需要指定网站根目录:

acme.sh --issue -d clsn.io --nginx

注意, 无论是 apache 还是 nginx 模式, acme.sh在完成验证之后, 会恢复到之前的状态, 都不会私自更改你本身的配置. 好处是你不用担心配置被搞坏。 该类型的配置有一个缺点, 你需要自己配置 ssl 的配置, 否则只能成功生成证书, 你的网站还是无法访问https. 但是为了安全, 你还是自己手动改配置吧. 如果你还没有运行任何 web 服务, 80 端口是空闲的, 那么 acme.sh 还能假装自己是一个webserver, 临时听在80 端口, 完成验证:

acme.sh --issue -d clsn.io --standalone

更高级的用法请参考: https://github.com/Neilpang/acme.sh/wiki/How-to-issue-a-cert

3.2 DNS方式

这种方式的好处是, 你不需要任何服务器, 不需要任何公网 ip, 只需要 dns 的解析记录即可完成验证。 这种方式的缺点是,如果不同时配置 Automatic DNS API,使用这种方式 acme.sh 将无法自动更新证书,每次都需要手动再次重新解析验证域名所有权。

3.2.1 颁发证书[[email protected] /opt] #cd /root/.acme.sh/ [[email protected] /root/.acme.sh] #acme.sh --issue -d *.clsn.io -d clsn.io --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please [2018年 11月 13日 星期二 15:34:55 CST] Creating domain key [2018年 11月 13日 星期二 15:34:55 CST] The domain key is here: /www/server/panel/vhost/cert/*.clsn.io/*.clsn.io.key [2018年 11月 13日 星期二 15:34:55 CST] Multi domain='DNS:*.clsn.io,DNS:clsn.io' [2018年 11月 13日 星期二 15:34:55 CST] Getting domain auth token for each domain [2018年 11月 13日 星期二 15:34:56 CST] Getting webroot for domain='*.clsn.io' [2018年 11月 13日 星期二 15:34:57 CST] Getting webroot for domain='clsn.io' [2018年 11月 13日 星期二 15:34:57 CST] Add the following TXT record: [2018年 11月 13日 星期二 15:34:57 CST] Domain: '_acme-challenge.clsn.io' [2018年 11月 13日 星期二 15:34:57 CST] TXT value: '9rj0bhiGrO9UJ44XgV0APXuGBRL1vOk4XKdsnnxaIf4' [2018年 11月 13日 星期二 15:34:57 CST] Please be aware that you prepend _acme-challenge. before your domain [2018年 11月 13日 星期二 15:34:57 CST] so the resulting subdomain will be: _acme-challenge.clsn.io [2018年 11月 13日 星期二 15:34:57 CST] Add the following TXT record: [2018年 11月 13日 星期二 15:34:57 CST] Domain: '_acme-challenge.clsn.io' [2018年 11月 13日 星期二 15:34:57 CST] TXT value: 'yJ4Ca9yVg1Fsp4RhH5XZJohh0eE3dFXEKM2KGUFNHio' [2018年 11月 13日 星期二 15:34:57 CST] Please be aware that you prepend _acme-challenge. before your domain [2018年 11月 13日 星期二 15:34:57 CST] so the resulting subdomain will be: _acme-challenge.clsn.io [2018年 11月 13日 星期二 15:34:57 CST] Please add the TXT records to the domains, and re-run with --renew. [2018年 11月 13日 星期二 15:34:57 CST] Please add '--debug' or '--log' to check more details. [2018年 11月 13日 星期二 15:34:57 CST] See: https://github.com/Neilpang/acme.sh/wiki/How-to-debug-acme.sh3.2.2 修改DNS

在NS管理方修改主机记录

3.2.3 验证解析是否生效

$dig -t txt _acme-challenge.clsn.io @8.8.8.8 ; DiG 9.9.7-P3 -t txt _acme-challenge.clsn.io @8.8.8.8 ;; global options: +cmd ;; Got answer: ;; ->>HEADER


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有