cloudflare自动续签ssl

一直用着cloudflare的免费证书,可后来发现我另外一个域名 mirageek.com 的证书第一次申请的时候是可以的,但是3个月后过期了居然没有自动续费。于是就找了下原因。

首先是通过api获取下不同域名之间的ssl差异。

1
curl "https://api.cloudflare.com/client/v4/zones/{zone_id}/custom_hostnames"    -H "Authorization: Bearer {api token}"

获得的结果如下:

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{
"id": "{id}",
"hostname": "blog.timoq.com",
"ssl": {
"id": "{id}",
"type": "dv",
"method": "http",
"status": "active",
"hosts": [
"blog.timoq.com"
],
"settings": {
"min_tls_version": "1.2"
},
"bundle_method": "ubiquitous",
"certificates": [
{
"issuer": "GoogleTrustServices",
"serial_number": "{number}",
"signature": "ECDSAWithSHA256",
"expires_on": "2026-11-07T17:30:09Z",
"issued_on": "2026-08-09T16:30:17Z",
"fingerprint_sha256": "{sha256}",
"id": "{id}"
},
{
"issuer": "GoogleTrustServices",
"serial_number": "{number}",
"signature": "SHA256WithRSA",
"expires_on": "2026-11-07T17:29:58Z",
"issued_on": "2026-08-09T16:30:02Z",
"fingerprint_sha256": "{sha256}",
"id": "{id}"
}
],
"wildcard": false,
"certificate_authority": "google"
},
"status": "active",
"created_at": "2024-08-29T02:58:59.648954Z"
}

{
"id": "{id}",
"hostname": "mirageek.com",
"ssl": {
"id": "{id}",
"type": "dv",
"method": "txt",
"status": "active",
"hosts": [
"mirageek.com"
],
"settings": {
"min_tls_version": "1.2"
},
"bundle_method": "ubiquitous",
"certificates": [
{
"issuer": "GoogleTrustServices",
"serial_number": "{number}",
"signature": "SHA256WithRSA",
"expires_on": "2026-11-21T15:48:09Z",
"issued_on": "2026-08-23T14:50:43Z",
"fingerprint_sha256": "{sha256}",
"id": "{id}"
},
{
"issuer": "GoogleTrustServices",
"serial_number": "{number}",
"signature": "ECDSAWithSHA256",
"expires_on": "2026-11-21T15:50:49Z",
"issued_on": "2026-08-23T14:50:55Z",
"fingerprint_sha256": "{sha256}",
"id": "{id}"
}
],
"wildcard": false,
"certificate_authority": "google"
},
"status": "active",
"created_at": "2026-08-23T15:48:09.572511Z"
},

仔细对比了以上内容,发现唯一的区别是自动续费的域名ssl.method是http,而不是自动续费的就是TXT。

那就容易了

1
2
3
4
5
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/custom_hostnames/{domain_id} \
-X PATCH \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer {api_token}" \
-d '{"ssl":{"method":"http","type":"dv"}}'