自动替换ssl证书
参考文章: 如何解决 SSL 证书问题
修改配置文件
具体看x.xxx.xx.xx.nginx.conf
acme.sh 在申请证书(HTTP-01 验证)时,CA 机构会访问你的域名: http://yourdomain.com/.well-known/acme-challenge/xxxx
如果没有任何例外,这个请求也会被 rewrite 到 HTTPS。如果此时你的 SSL 证书已经过期或还没申请下来,验证服务器可能就无法完成访问,导致证书申请失败。
conf
# 80端口之前
# 在`强制全站跳转 HTTPS`的大规则下,开一个小后门,允许 HTTP 验证请求通过
server {
listen 80;
server_name relaxing.top;
location ^~ /.well-known/acme-challenge/ {
root /usr/share/nginx/html;
allow all;
}
location / {
return 301 https://$host$request_uri;
}
}- 外部请求到达:CA 机构访问 /.well-known/acme-challenge/abc...
- 匹配 location:Nginx 发现这个 URL 匹配到了 ^~ /.well-known/acme-challenge/。
- 停止跳转:因为 ^~ 的优先级很高,Nginx 会忽略后面那个把所有流量转到 HTTPS 的 rewrite 指令。
- 读取文件:Nginx 直接去 /usr/share/nginx/html/.well-known/acme-challenge/ 目录下读取验证文件并返回给 CA 机构。
- 验证成功:证书下发
开始签发
申请颁发
bash
acme.sh --issue -d relaxing.top -w /usr/share/nginx/html
acme.sh --issue -d api.relaxing.top -w /usr/share/nginx/html
acme.sh --issue -d minio.relaxing.top -w /usr/share/nginx/htmltxt
[root@fang nginx]# acme.sh --issue -d relaxing.top -w /usr/share/nginx/html
[2026年 01月 31日 星期六 18:09:11 CST] Using CA: https://acme-v02.api.letsencrypt.org/directory
[2026年 01月 31日 星期六 18:09:11 CST] Single domain='relaxing.top'
[2026年 01月 31日 星期六 18:09:18 CST] Getting webroot for domain='relaxing.top'
[2026年 01月 31日 星期六 18:09:19 CST] Verifying: relaxing.top
[2026年 01月 31日 星期六 18:09:20 CST] Pending. The CA is processing your order, please wait. (1/30)
[2026年 01月 31日 星期六 18:09:24 CST] Success
[2026年 01月 31日 星期六 18:09:24 CST] Verification finished, beginning signing.
[2026年 01月 31日 星期六 18:09:24 CST] Let's finalize the order.
[2026年 01月 31日 星期六 18:09:24 CST] Le_OrderFinalize='https://acme-v02.api.letsencrypt.org/acme/finalize/3016909216/475361502666'
[2026年 01月 31日 星期六 18:09:29 CST] Downloading cert.
[2026年 01月 31日 星期六 18:09:29 CST] Le_LinkCert='https://acme-v02.api.letsencrypt.org/acme/cert/05905b8d8629e8729a915c05900c4a3da1b1'
[2026年 01月 31日 星期六 18:09:31 CST] Cert success.
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
[2026年 01月 31日 星期六 18:09:31 CST] Your cert is in: /root/.acme.sh/relaxing.top_ecc/relaxing.top.cer
[2026年 01月 31日 星期六 18:09:31 CST] Your cert key is in: /root/.acme.sh/relaxing.top_ecc/relaxing.top.key
[2026年 01月 31日 星期六 18:09:31 CST] The intermediate CA cert is in: /root/.acme.sh/relaxing.top_ecc/ca.cer
[2026年 01月 31日 星期六 18:09:31 CST] And the full-chain cert is in: /root/.acme.sh/relaxing.top_ecc/fullchain.cer安装证书
bash
acme.sh --install-cert -d relaxing.top \
--key-file /etc/ssl/relaxing_nginx/relaxing.top.key \
--fullchain-file /etc/ssl/relaxing_nginx/relaxing.top.pem \
--reloadcmd "systemctl reload nginx"
acme.sh --install-cert -d api.relaxing.top \
--key-file /etc/ssl/api/api.relaxing.top.key \
--fullchain-file /etc/ssl/api/api.relaxing.top.pem \
--reloadcmd "systemctl reload nginx"
acme.sh --install-cert -d minio.relaxing.top \
--key-file /etc/ssl/minio/minio.relaxing.top.key \
--fullchain-file /etc/ssl/minio/minio.relaxing.top.pem \
--reloadcmd "systemctl reload nginx"[root@fang html]# acme.sh --install-cert -d relaxing.top \
> --key-file /etc/ssl/relaxing_nginx/relaxing.top.key \
> --fullchain-file /etc/ssl/relaxing_nginx/relaxing.top.pem \
> --reloadcmd "systemctl reload nginx"
[2026年 01月 31日 星期六 18:12:22 CST] The domain 'relaxing.top' seems to already have an ECC cert, let's use it.
[2026年 01月 31日 星期六 18:12:22 CST] Installing key to: /etc/ssl/relaxing_nginx/relaxing.top.key
[2026年 01月 31日 星期六 18:12:22 CST] Installing full chain to: /etc/ssl/relaxing_nginx/relaxing.top.pem
[2026年 01月 31日 星期六 18:12:22 CST] Running reload cmd: systemctl reload nginx
[2026年 01月 31日 星期六 18:12:22 CST] Reload successful命令
bash
# 管理证书状态
acme.sh --list
# 强制续签
cme.sh --renew -d img.cdn.XXX.cn --force问题
需要绑定邮箱
txt
[root@fang nginx]# acme.sh --issue -d relaxing.top -w /usr/share/nginx/html
[2026年 01月 31日 星期六 18:00:35 CST] Using CA: <https://acme.zerossl.com/v2/DV90>
[2026年 01月 31日 星期六 18:00:35 CST] Account key creation OK.
[2026年 01月 31日 星期六 18:00:35 CST] No EAB credentials found for ZeroSSL, let's obtain them
[2026年 01月 31日 星期六 18:00:35 CST] acme.sh is using ZeroSSL as default CA now.
[2026年 01月 31日 星期六 18:00:35 CST] Please update your account with an email address first.
[2026年 01月 31日 星期六 18:00:35 CST] acme.sh --register-account -m <my@example.com>
[2026年 01月 31日 星期六 18:00:35 CST] See: <https://github.com/acmesh-official/acme.sh/wiki/ZeroSSL.com-CA>
[2026年 01月 31日 星期六 18:00:35 CST] Please add '--debug' or '--log' to see more information.
[2026年 01月 31日 星期六 18:00:35 CST] See: <https://github.com/acmesh-official/acme.sh/wiki/How-to-debug-acme.sh>bash
# 解决方案 使用letsencrypt
acme.sh --set-default-ca --server letsencrypt
