HTTPS证书的签发

记录一遍不同方式的HTTPS证书签发流程。

一、概述

1.1 证书签发工具

自动化签发HTTPS证书,有两种工具,这里准备在内网证书签发,内网没问题的话,公网可能也没问题。

  • acme.sh 方式
  • certbot 方式

1.2 DV、OV、EV的区别

类型 全称 验证方式 颁发速度 价格 浏览器显示 谁在用
DV Domain Validation (域名验证) 只验域名控制权 秒批 (自动化) 免费 / 便宜 🔒 小锁头 个人博客、中小企业、你和我
OV Organization Validation (组织验证) 验域名 + 人工核验公司营业执照 1-3 天 几百~几千元 🔒 小锁头 + 证书详情里有公司名 很多正规企业官网
EV Extended Validation (增强验证) 地狱级核验 (甚至会打公司座机电话确认) 3-7 天 巨贵 以前显示绿色公司名,现在只显锁 银行、金融机构、支付平台

1.3 域名验证方式

CA机构(Let’s Encrypt)有两种方式来验证域名的所有者,内网机器肯定无法使用HTTP的方式。

  • HTTP,http://你的域名/.well-known/...
  • DNS,添加一条CA机构指定的TXT记录

二、环境准备

  • 本地主机:192.168.10.18
  • 域名:qiaoxiong.cc
  • Git

三、ACME

Github仓库

3.1 安装

raw.githubusercontent.com 域名被墙,境内可能无法安装。

通过下载离线包,或者使用代理地址克隆仓库。此处使用https://g.bravexist.cn

3.1.1 离线安装

  1. 克隆仓库
1
git clone https://github.com/acmesh-official/acme.sh
1
git clone https://g.bravexist.cn/https://github.com/acmesh-official/acme.sh
  1. 下载离线包(二选一即可)
1
wget -O acme.sh-master.zip https://g.bravexist.cn/https://github.com/acmesh-official/acme.sh/archive/refs/heads/master.zip
  1. 安装
1
2
cd acme.sh
./acme.sh --install -m 自定义邮箱

安装结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@study-linux acme.sh]# ./acme.sh --install -m admin@007890.xyz
[2025年 12月 06日 星期六 11:30:33 CST] It is recommended to install socat first.
[2025年 12月 06日 星期六 11:30:33 CST] We use socat for the standalone server, which is used for standalone mode.
[2025年 12月 06日 星期六 11:30:33 CST] If you don't want to use standalone mode, you may ignore this warning.
[2025年 12月 06日 星期六 11:30:33 CST] Installing to /root/.acme.sh
[2025年 12月 06日 星期六 11:30:33 CST] Installed to /root/.acme.sh/acme.sh
[2025年 12月 06日 星期六 11:30:33 CST] Installing alias to '/root/.bashrc'
[2025年 12月 06日 星期六 11:30:33 CST] Close and reopen your terminal to start using acme.sh
[2025年 12月 06日 星期六 11:30:33 CST] Installing alias to '/root/.cshrc'
[2025年 12月 06日 星期六 11:30:33 CST] Installing alias to '/root/.tcshrc'
[2025年 12月 06日 星期六 11:30:33 CST] Installing cron job
no crontab for root
no crontab for root
[2025年 12月 06日 星期六 11:30:33 CST] bash has been found. Changing the shebang to use bash as preferred.
[2025年 12月 06日 星期六 11:30:35 CST] OK
  1. 刷新环境变量,否则没有 acme.sh 的命令
1
source ~/.bashrc
  1. 验证
1
acme.sh --version

3.1.2 在线安装

raw.githubusercontent.com 域名被墙,境内可能无法安装。

  1. 在线安装
1
curl https://get.acme.sh | sh -s email=my@example.com
1
wget -O -  https://get.acme.sh | sh -s email=my@example.com
  1. 刷新环境变量,否则没有 acme.sh 的命令
1
source ~/.bashrc
  1. 验证
1
acme.sh --version

3.1.3 切换CA机构

ZeroSSL 在国内网络环境有时候极其不稳定.

1
acme.sh --set-default-ca --server letsencrypt

3.2 手动添加 DNS TXT 记录

test.qiaoxiong.cc

步骤一、申请证书

1
acme.sh --issue --dns dns_manual -d test.qiaoxiong.cc
  • --issue: 表示这是一个签发证书的命令
  • --dns: 表示使用DNS验证方式验证您拥有域名的控制权
  • -d--domain : 要签发证书的域名
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@study-linux ~]# acme.sh --issue --dns dns_manual -d test.qiaoxiong.cc
[2025年 12月 06日 星期六 12:09:57 CST] Using CA: https://acme-v02.api.letsencrypt.org/directory
[2025年 12月 06日 星期六 12:09:57 CST] Creating domain key
[2025年 12月 06日 星期六 12:09:57 CST] The domain key is here: /root/.acme.sh/test.qiaoxiong.cc_ecc/test.qiaoxiong.cc.key
[2025年 12月 06日 星期六 12:09:57 CST] Single domain='test.qiaoxiong.cc'
[2025年 12月 06日 星期六 12:10:02 CST] Getting webroot for domain='test.qiaoxiong.cc'
[2025年 12月 06日 星期六 12:10:02 CST] Cannot find DNS API hook for: dns_manual
[2025年 12月 06日 星期六 12:10:02 CST] You need to add the TXT record manually.
[2025年 12月 06日 星期六 12:10:02 CST] Add the following TXT record:
[2025年 12月 06日 星期六 12:10:02 CST] Domain: '_acme-challenge.test.qiaoxiong.cc'
[2025年 12月 06日 星期六 12:10:02 CST] TXT value: '5zzhFDQs85hzL-grMerXpuV5gYRA3h95zmWNX1MvfeE'
[2025年 12月 06日 星期六 12:10:02 CST] Please make sure to prepend '_acme-challenge.' to your domain
[2025年 12月 06日 星期六 12:10:02 CST] so that the resulting subdomain is: _acme-challenge.test.qiaoxiong.cc
[2025年 12月 06日 星期六 12:10:02 CST] Please add the TXT records to the domains, and re-run with --renew.
[2025年 12月 06日 星期六 12:10:02 CST] Please add '--debug' or '--log' to see more information.
[2025年 12月 06日 星期六 12:10:02 CST] See: https://github.com/acmesh-official/acme.sh/wiki/How-to-debug-acme.sh
[root@study-linux ~]#

步骤二、看提示,需要添加

1
2
_acme-challenge.test.qiaoxiong.cc
5zzhFDQs85hzL-grMerXpuV5gYRA3h95zmWNX1MvfeE

使用 nslookup 验证

1
nslookup -type=txt _acme-challenge.test.qiaoxiong.cc

步骤三、添加TXT记录后,继续执行

1
acme.sh --renew -d test.qiaoxiong.cc --dns dns_manual
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[root@study-linux ~]# acme.sh --renew -d test.qiaoxiong.cc --dns dns_manual
[2025年 12月 06日 星期六 12:12:00 CST] The domain 'test.qiaoxiong.cc' seems to already have an ECC cert, let's use it.
[2025年 12月 06日 星期六 12:12:00 CST] Renewing: 'test.qiaoxiong.cc'
[2025年 12月 06日 星期六 12:12:00 CST] Renewing using Le_API=https://acme-v02.api.letsencrypt.org/directory
[2025年 12月 06日 星期六 12:12:02 CST] Using CA: https://acme-v02.api.letsencrypt.org/directory
[2025年 12月 06日 星期六 12:12:02 CST] Single domain='test.qiaoxiong.cc'
[2025年 12月 06日 星期六 12:12:07 CST] Getting webroot for domain='test.qiaoxiong.cc'
[2025年 12月 06日 星期六 12:12:07 CST] test.qiaoxiong.cc is already verified, skipping dns-01.
[2025年 12月 06日 星期六 12:12:07 CST] Verification finished, beginning signing.
[2025年 12月 06日 星期六 12:12:07 CST] Let's finalize the order.
[2025年 12月 06日 星期六 12:12:07 CST] Le_OrderFinalize='https://acme-v02.api.letsencrypt.org/acme/finalize/2855083586/456009277126'
[2025年 12月 06日 星期六 12:12:09 CST] Downloading cert.
[2025年 12月 06日 星期六 12:12:09 CST] Le_LinkCert='https://acme-v02.api.letsencrypt.org/acme/cert/05b8918f64493c18b5b805b2c46634519ac8'
[2025年 12月 06日 星期六 12:12:11 CST] Cert success.
-----BEGIN CERTIFICATE-----
MIIDljCCAxygAwIBAgISBbiRj2RJPBi1uAWyxGY0UZrIMAoGCCqGSM49BAMDMDIx
CzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQDEwJF
ODAeFw0yNTEyMDYwMzEzMzhaFw0yNjAzMDYwMzEzMzdaMBwxGjAYBgNVBAMTEXRl
c3QucWlhb3hpb25nLmNjMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEhE6BEA0u
lck+GGEnQDvbBfW978L7jpR2EdSbwGecttgwZY/Un9juilQJEZ/pC/U6HfS3aXqK
vS0g3TfrkE6ZIKOCAiYwggIiMA4GA1UdDwEB/wQEAwIHgDAdBgNVHSUEFjAUBggr
BgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQU2Q+pcKYa
FreFRgT9EZJYkRwgGckwHwYDVR0jBBgwFoAUjw0TovYuftFQbDMYOF1ZjiNykcow
MgYIKwYBBQUHAQEEJjAkMCIGCCsGAQUFBzAChhZodHRwOi8vZTguaS5sZW5jci5v
cmcvMBwGA1UdEQQVMBOCEXRlc3QucWlhb3hpb25nLmNjMBMGA1UdIAQMMAowCAYG
Z4EMAQIBMC0GA1UdHwQmMCQwIqAgoB6GHGh0dHA6Ly9lOC5jLmxlbmNyLm9yZy83
My5jcmwwggELBgorBgEEAdZ5AgQCBIH8BIH5APcAdQBkEcRspBLsp4kcogIuALyr
TygH1B41J6vq/tUDyX3N8AAAAZrx3ClwAAAEAwBGMEQCIFSqgIHjsMeguIoLwBdE
as06xXFwvHROnO11G71OMTC0AiBjFPZzhnD4xan53IFNl+ZsM9uRQBRrv+zqOdq2
Pg26twB+AOMjjfKNoojgquCs8PqQyYXwtr/10qUnsAH8HERYxLboAAABmvHcK7MA
CAAABQAo5aReBAMARzBFAiBsttbLfEAHu3ZHQusA4c0crZtY93BiROITcpvGRNKq
RQIhAKIdhLA1DkKy4zASvuvVSH85Bn1hyLxGl0IJ3BPV6aHAMAoGCCqGSM49BAMD
A2gAMGUCMQDNbN9iCAZH0ZefXWmDU8+I1UyY1zDxPnS8TZFaZLhs8esGU93uIfhD
7tHYDygLu5ACMByb9uf4KpdbOkukz+r93YW4QBwMhRvggGqnPoSVwQq2pnWpI/hn
zhfR7BEUIIGFAw==
-----END CERTIFICATE-----
[2025年 12月 06日 星期六 12:12:11 CST] Your cert is in: /root/.acme.sh/test.qiaoxiong.cc_ecc/test.qiaoxiong.cc.cer
[2025年 12月 06日 星期六 12:12:11 CST] Your cert key is in: /root/.acme.sh/test.qiaoxiong.cc_ecc/test.qiaoxiong.cc.key
[2025年 12月 06日 星期六 12:12:11 CST] The intermediate CA cert is in: /root/.acme.sh/test.qiaoxiong.cc_ecc/ca.cer
[2025年 12月 06日 星期六 12:12:11 CST] And the full-chain cert is in: /root/.acme.sh/test.qiaoxiong.cc_ecc/fullchain.cer
[root@study-linux ~]#

步骤四、安装证书

  1. 创建证书文件夹
1
mkdir -p /etc/nginx/ssl/test.qiaoxiong.cc
  1. 安装证书
1
2
3
4
acme.sh --install-cert -d test.qiaoxiong.cc --ecc \
--key-file /etc/nginx/ssl/test.qiaoxiong.cc/server.key \
--fullchain-file /etc/nginx/ssl/test.qiaoxiong.cc/server.pem \
--reloadcmd "systemctl reload nginx"
  • --reloadcmd 会自动重启Nginx(可选参数)
  1. nginx配置SSL站点示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
server {
# 1.25版本以后,ssl http2 需要新开一行,否则会警告
listen 443 ssl http2;
server_name test.qiaoxiong.cc;

# 引用刚才安装命令里指定的文件路径
ssl_certificate /etc/nginx/ssl/test.qiaoxiong.cc/server.pem;
ssl_certificate_key /etc/nginx/ssl/test.qiaoxiong.cc/server.key;

# 推荐的安全套件配置
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;

location / {
# 你的网站根目录或者反向代理
root /usr/share/nginx/html;
index index.html;
}
}

# 强制 HTTP 转 HTTPS
server {
listen 80;
server_name test.qiaoxiong.cc;
return 301 https://$host$request_uri;
}

步骤五、续签

1
acme.sh --renew -d test.qiaoxiong.cc --dns dns_manual

Let’s Encrypt 的证书有效期是 90 天acme.sh 默认逻辑是:只有当证书剩下的寿命少于 30 天时,才会执行 renew。 当然可以强制签发,但是同一域名,每周只能签发 5 次 重复证书。

查看证书信息

  • acme.sh 的方式
1
acme.sh --info -d test.qiaoxiong.cc
  • openssl 查看详细信息
1
openssl x509 -in /etc/nginx/ssl/test.qiaoxiong.cc/server.pem -noout -text

3.3 DNS API自动添加TXT记录

DNS API 官方文档

目前(2025年12月),支持170+ DNS服务商,这里以Cloudflare为例。

demo.qiaoxiong.cc

步骤一、获取token和账户ID

  1. 获取Token

个人简介>>>配置文件>>>API令牌>>>创建令牌>>>编辑区域DNS>>>(为令牌设置名称、选域名、设置令牌过期时间)

1
ReQhAZC9bgK_J1Ly-vHp4n8pvIwEzc5gQeK8SAt6
  1. 获取账户ID,Account ID

点击任意域名,概述,右下角,账户ID

1
d28018db2f766e853db5132afc6cc34a

步骤二、申请证书

  1. 讲Token写入环境变量中
1
2
export CF_Token="你的_Token_字符串"
export CF_Account_ID="你的_Account_ID"
  1. 开始签发
1
acme.sh --issue --dns dns_cf -d demo.qiaoxiong.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
[root@study-linux ~]# acme.sh --issue --dns dns_cf -d demo.qiaoxiong.cc
[2025年 12月 06日 星期六 15:05:13 CST] Using CA: https://acme-v02.api.letsencrypt.org/directory
[2025年 12月 06日 星期六 15:05:13 CST] Creating domain key
[2025年 12月 06日 星期六 15:05:13 CST] The domain key is here: /root/.acme.sh/demo.qiaoxiong.cc_ecc/demo.qiaoxiong.cc.key
[2025年 12月 06日 星期六 15:05:13 CST] Single domain='demo.qiaoxiong.cc'
[2025年 12月 06日 星期六 15:05:21 CST] Getting webroot for domain='demo.qiaoxiong.cc'
[2025年 12月 06日 星期六 15:05:21 CST] Adding TXT value: JnMJesmR8R0THgTcKCbKA_D2MB5JlIh2prOfweLxdIw for domain: _acme-challenge.demo.qiaoxiong.cc
[2025年 12月 06日 星期六 15:05:36 CST] Adding record
[2025年 12月 06日 星期六 15:05:37 CST] Added, OK
[2025年 12月 06日 星期六 15:05:37 CST] The TXT record has been successfully added.
[2025年 12月 06日 星期六 15:05:37 CST] Let's check each DNS record now. Sleeping for 20 seconds first.
[2025年 12月 06日 星期六 15:05:59 CST] You can use '--dnssleep' to disable public dns checks.
[2025年 12月 06日 星期六 15:05:59 CST] See: https://github.com/acmesh-official/acme.sh/wiki/dnscheck
[2025年 12月 06日 星期六 15:05:59 CST] Checking demo.qiaoxiong.cc for _acme-challenge.demo.qiaoxiong.cc
[2025年 12月 06日 星期六 15:06:06 CST] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 7
[2025年 12月 06日 星期六 15:06:14 CST] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 7
[2025年 12月 06日 星期六 15:06:20 CST] Success for domain demo.qiaoxiong.cc '_acme-challenge.demo.qiaoxiong.cc'.
[2025年 12月 06日 星期六 15:06:20 CST] All checks succeeded
[2025年 12月 06日 星期六 15:06:20 CST] Verifying: demo.qiaoxiong.cc
[2025年 12月 06日 星期六 15:06:22 CST] Pending. The CA is processing your order, please wait. (1/30)
[2025年 12月 06日 星期六 15:06:26 CST] Success
[2025年 12月 06日 星期六 15:06:26 CST] Removing DNS records.
[2025年 12月 06日 星期六 15:06:26 CST] Removing txt: JnMJesmR8R0THgTcKCbKA_D2MB5JlIh2prOfweLxdIw for domain: _acme-challenge.demo.qiaoxiong.cc
[2025年 12月 06日 星期六 15:06:41 CST] Successfully removed
[2025年 12月 06日 星期六 15:06:41 CST] Verification finished, beginning signing.
[2025年 12月 06日 星期六 15:06:41 CST] Let's finalize the order.
[2025年 12月 06日 星期六 15:06:41 CST] Le_OrderFinalize='https://acme-v02.api.letsencrypt.org/acme/finalize/2855083586/456048474936'
[2025年 12月 06日 星期六 15:06:43 CST] Downloading cert.
[2025年 12月 06日 星期六 15:06:43 CST] Le_LinkCert='https://acme-v02.api.letsencrypt.org/acme/cert/05ae4237df1ae9469af06fa3bfcf5b1b9b73'
[2025年 12月 06日 星期六 15:06:46 CST] Cert success.
-----BEGIN CERTIFICATE-----
MIIDkTCCAxagAwIBAgISBa5CN98a6Uaa8G+jv89bG5tzMAoGCCqGSM49BAMDMDIx
CzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQDEwJF
ODAeFw0yNTEyMDYwNjA4MTJaFw0yNjAzMDYwNjA4MTFaMBwxGjAYBgNVBAMTEWRl
bW8ucWlhb3hpb25nLmNjMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/Vj5IKbD
IfSLMkDu6047dD9JxVdeG6hAZxDhRUkEfseHySeEVdrBXAOrfUoe8LTTWOEHltkc
g/5tL7bLcrHj36OCAiAwggIcMA4GA1UdDwEB/wQEAwIHgDAdBgNVHSUEFjAUBggr
BgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQU44k7QU+S
qN14tf8L27ogV9HwvKAwHwYDVR0jBBgwFoAUjw0TovYuftFQbDMYOF1ZjiNykcow
MgYIKwYBBQUHAQEEJjAkMCIGCCsGAQUFBzAChhZodHRwOi8vZTguaS5sZW5jci5v
cmcvMBwGA1UdEQQVMBOCEWRlbW8ucWlhb3hpb25nLmNjMBMGA1UdIAQMMAowCAYG
Z4EMAQIBMC4GA1UdHwQnMCUwI6AhoB+GHWh0dHA6Ly9lOC5jLmxlbmNyLm9yZy8x
MTYuY3JsMIIBBAYKKwYBBAHWeQIEAgSB9QSB8gDwAHYADleUvPOuqT4zGyyZB7P3
kN+bwj1xMiXdIaklrGHFTiEAAAGa8nv7DgAABAMARzBFAiEA0fWHbDaVu8ZM/88n
vs4L3w48uNBNTcsuMorai9RUazECIApxooh2LJi1EsU9Txc5mCFyq+P3jQBoY3D5
m5C5MHd0AHYA0W6ppWgHfmY1oD83pd28A6U8QRIU1IgY9ekxsyPLlQQAAAGa8nv7
8QAABAMARzBFAiEA3zMUhuoGSUKsQvyaPX7Qh5ASW76m68p9T4R+603VseACIG4d
8wR19QB1i3GH9H4YQCmRmM1dGvKHfeN5YFeZnoFOMAoGCCqGSM49BAMDA2kAMGYC
MQCU3nFNUICzgKxMdom/9aBe70bc1youQGms3wIFhMZm6IBKpHzcG56FTj7doeHU
W44CMQD56bYByNv245snFPypclg7wOqMP0EA+8Trrr3MwmYyrzhdRnXYClA4EXB+
8nTc38s=
-----END CERTIFICATE-----
[2025年 12月 06日 星期六 15:06:46 CST] Your cert is in: /root/.acme.sh/demo.qiaoxiong.cc_ecc/demo.qiaoxiong.cc.cer
[2025年 12月 06日 星期六 15:06:46 CST] Your cert key is in: /root/.acme.sh/demo.qiaoxiong.cc_ecc/demo.qiaoxiong.cc.key
[2025年 12月 06日 星期六 15:06:46 CST] The intermediate CA cert is in: /root/.acme.sh/demo.qiaoxiong.cc_ecc/ca.cer
[2025年 12月 06日 星期六 15:06:46 CST] And the full-chain cert is in: /root/.acme.sh/demo.qiaoxiong.cc_ecc/fullchain.cer
[root@study-linux ~]#

步骤三,安装证书

安装证书同 3.2的步骤四

步骤四,续签

在证书小于30天过期时,acme.sh 会自动续签证书。

步骤五,擦除环境变量,可选

1
unset CF_Token CF_Account_ID

四、CertBot

Certbot是 EFF(电子前哨基金会)官方出品,基于 Python,功能最全,但也最庞大。

依赖python3、各种功能需要安装对应的插件。

最佳做法,按照官方文档操作。

4.1 安装

  1. 安装python3,pip3
1
yum install python3 python3-pip

注意:python版本太久容易遇到一些依赖问题。

  1. 安装certbot 本体
1
pip3 install certbot
  1. 旧版本python3.6容易遇到依赖问题,卸载依赖的库,安装最后支持的特定版本
1
pip3 uninstall -y cryptography pyopenssl
1
pip3 install "cryptography<37" "pyopenssl<22"

4.2 手动添加 DNS TXT记录

certbot.qiaoxiong.cc

步骤一

  1. 申请证书
1
certbot certonly --manual --preferred-challenges dns -d certbot.qiaoxiong.cc
  1. 输入电子邮箱(交互式输入)
1
2
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel):
  1. 同意协议(必须填Yes)
1
2
3
4
5
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.6-August-18-2025.pdf. You must agree
in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:
  1. 是否同意共享电子邮件给EFF(可选No)
1
2
3
4
5
6
7
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:
  1. 需要在DNS中添加TXT记录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@study-linux ~]# certbot certonly --manual --preferred-challenges dns -d certbot.qiaoxiong.cc
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Python 3.6 support will be dropped in the next release of Certbot - please upgrade your Python version.
Requesting a certificate for certbot.qiaoxiong.cc

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.certbot.qiaoxiong.cc.

with the following value:

gUEIns1FvCNFSXxubJZdqupCr6wQ73P37PS9KY_06rI

Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.certbot.qiaoxiong.cc.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

步骤二,添加记录

1
2
_acme-challenge.certbot.qiaoxiong.cc.
gUEIns1FvCNFSXxubJZdqupCr6wQ73P37PS9KY_06rI

步骤三,验证记录

1
nslookup -type=txt _acme-challenge.certbot.qiaoxiong.cc.

步骤四,回车继续申请,

需要注意申请成功后显示的证书路径是软连接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/certbot.qiaoxiong.cc/fullchain.pem
Key is saved at: /etc/letsencrypt/live/certbot.qiaoxiong.cc/privkey.pem
This certificate expires on 2026-03-06.
These files will be updated when the certificate renews.

NEXT STEPS:
- This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[root@study-linux ~]#

步骤五,安装证书

  • 法一:在Nginx配置中启用SSL证书
1
2
3
4
5
6
7
8
9
10
11
12
13
server {
listen 443 ssl;
server_name certbot.qiaoxiong.cc;

# === 直接指向 Certbot 的目录 ===
ssl_certificate /etc/letsencrypt/live/certbot.qiaoxiong.cc/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/certbot.qiaoxiong.cc/privkey.pem;

location / {
root /usr/share/nginx/html;
index index.html;
}
}
  • 法二,手动复制证书到指定目录后,在Nginx配置中启用SSL证书
  1. 建目录
1
mkdir -p /etc/nginx/ssl/certbot.qiaoxiong.cc
  1. 只有手动 CP (注意:这里要复制真实文件,而不是软链接,或者用 -L)
1
2
cp -L /etc/letsencrypt/live/certbot.qiaoxiong.cc/fullchain.pem /etc/nginx/ssl/certbot.qiaoxiong.cc/server.pem
cp -L /etc/letsencrypt/live/certbot.qiaoxiong.cc/privkey.pem /etc/nginx/ssl/certbot.qiaoxiong.cc/server.key
  1. 修改Nginx配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
listen 443 ssl http2;
server_name certbot.qiaoxiong.cc;

ssl_certificate /etc/nginx/ssl/certbot.qiaoxiong.cc/server.pem;
ssl_certificate_key /etc/nginx/ssl/certbot.qiaoxiong.cc/server.key;

# 安全优化
ssl_protocols TLSv1.2 TLSv1.3;

location / {
return 200 "Certbot success!";
}
}
  1. 检查配置
1
nginx -t
  1. 重载配置
1
systemctl restart nginx

4.3 DNS API自动添加TXT记录

CertBot 支持的DNS不如Acme.sh,这里以Cloudflare为例。

auto.qiaoxiong.cc

步骤一,环境准备

  1. 安装插件
1
pip3 install certbot-dns-cloudflare
  1. 获取Token

个人简介>>>配置文件>>>API令牌>>>创建令牌>>>编辑区域DNS>>>(为令牌设置名称、选域名、设置令牌过期时间)

1
ENfVsdVvOGDdRfXzNBVhu7C_Nzy25_qkIrOalB7d
  1. 创建密钥文件,并写入密钥
1
2
mkdir -p ~/.secrets/certbot
vim ~/.secrets/certbot/cloudflare.ini
1
2
# Target DNS Provider: Cloudflare
dns_cloudflare_api_token = 你的_Token_字符串
  1. 设置最小权限
1
chmod 600 ~/.secrets/certbot/cloudflare.ini

步骤二,申请证书

需要注意申请成功后显示的证书路径是软连接

1
2
3
4
5
certbot certonly \
--dns-cloudflare \
--dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \
--dns-cloudflare-propagation-seconds 60 \
-d auto.qiaoxiong.cc
  • certonly: 只拿证书,不自动修改 Nginx 配置(推荐)。

  • --dns-cloudflare: 告诉它使用刚装的那个插件。

  • --dns-cloudflare-credentials: 告诉它钥匙在哪里。

  • --dns-cloudflare-propagation-seconds 60: 防坑参数。意思是“提交 API 后,强制发呆 60 秒”。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@study-linux ~]# certbot certonly \
> --dns-cloudflare \
> --dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \
> --dns-cloudflare-propagation-seconds 60 \
> -d auto.qiaoxiong.cc
> -d auto.qiaoxiong.cc
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Python 3.6 support will be dropped in the next release of Certbot - please upgrade your Python version.
Requesting a certificate for auto.qiaoxiong.cc

......

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/auto.qiaoxiong.cc/fullchain.pem
Key is saved at: /etc/letsencrypt/live/auto.qiaoxiong.cc/privkey.pem
This certificate expires on 2026-03-06.
These files will be updated when the certificate renews.

NEXT STEPS:
- The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[root@study-linux ~]#

步骤三,安装证书

同 4.2章节的 步骤五

4.4 自动续签

yum/apt 安装的系统包才会自动配置 systemd timer. pip 的方式需手动配置。

写入计划任务

1
crontab -e
1
0 0,12 * * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && sudo certbot renew -q

五、参考资料