...
运维

免费SSL证书、自动化续签证书,acme.sh 完整教程:安装、使用、常见错误及解决方案

1. 什么是 acme.sh?

acme.sh 是一个 ACME 客户端,用于申请、安装和自动更新 SSL/TLS 证书,例如 Let’s Encrypt 和 ZeroSSL 证书。相比 Certbot,acme.sh 更轻量、依赖少、支持多种 CA 及自动化功能。

2. acme.sh 的特点

  • 纯 Shell 实现,无 Python 或 OpenSSL 依赖。
  • 支持多种 CA:默认使用 Let’s Encrypt,也支持 ZeroSSL、Buypass、SSL.com 等。
  • 多种验证方式:HTTP、Standalone、DNS API。
  • 支持通配符证书*.example.com)。
  • 自动续期,无需手动更新证书。
  • 灵活部署,可自动安装证书到 Nginx、Apache、HAProxy 等。

3. 国内安装 acme.sh

3.1. 使用国内镜像安装(推荐)

由于国内访问 GitHub 可能较慢,可以使用 Gitee 镜像安装:

curl https://gitee.com/neilpang/acme.sh/raw/master/acme.sh | sh

安装完成后,acme.sh 位于 ~/.acme.sh/ 目录。

3.2. 重新加载 Shell 以生效

source ~/.bashrc  # 或者 source ~/.zshrc

3.3. 验证安装

acme.sh --version

4. 申请 SSL 证书

acme.sh 提供多种方式申请证书。

4.1. 使用 Webroot 方式(适用于已运行的 Web 服务器)

acme.sh --issue -d example.com -d www.example.com --webroot /var/www/html

4.2. 使用 Standalone 方式(适用于无 Web 服务器的情况)

acme.sh --issue -d example.com --standalone

注意:需要确保 80 端口未被占用。

4.3. 使用 DNS API 方式(适用于通配符证书)

export Ali_Key="你的阿里云 AccessKey ID"
export Ali_Secret="你的阿里云 AccessKey Secret"
acme.sh --issue -d example.com -d "*.example.com" --dns dns_ali

支持的 DNS API:阿里云(dns_ali)、腾讯云(dns_dp)、Cloudflare(dns_cf)等。


5. 安装证书

acme.sh --install-cert -d example.com \
  --key-file /etc/nginx/ssl/example.com.key \
  --fullchain-file /etc/nginx/ssl/example.com.crt \
  --reloadcmd "systemctl reload nginx"

6. 证书续期

acme.sh 会自动续期证书,也可手动执行:

acme.sh --renew -d example.com

或者续期所有证书:

acme.sh --renew-all

6.1. 设置自动续期(默认已启用)

acme.sh 默认会自动续期证书,但如果需要手动确认,可以执行:

acme.sh --cron --home ~/.acme.sh

此外,可以在 crontab 中检查是否存在 acme.sh 的自动任务:

crontab -l

如果不存在,可手动添加(每天 0 点执行):

echo "0 0 * * * ~/.acme.sh/acme.sh --cron --home ~/.acme.sh > /dev/null" | crontab -

7. 解决常见错误

7.1. ZeroSSL 需要注册账户

错误信息:

[Tue Apr  1 09:49:07 CST 2025] No EAB credentials found for ZeroSSL, let's obtain them
[Tue Apr  1 09:49:07 CST 2025] Please update your account with an email address first.

解决方案:

acme.sh --register-account -m my@example.com

7.2. Let’s Encrypt 速率限制(Rate Limit)

错误信息:

[Tue Apr  1 09:51:14 CST 2025] Error creating new order. Le_OrderFinalize not found.
"type": "urn:ietf:params:acme:error:rateLimited",

解决方案:

  • 等待 7 天后再尝试。
  • 使用已有证书 acme.sh --install-cert
  • 改用 ZeroSSL acme.sh --set-default-ca --server zerossl
  • 测试时使用 Let’s Encrypt staging 服务器。

7.3. Nginx 端口占用问题

错误信息:

acme.sh --issue --standalone 失败

解决方案:

systemctl stop nginx
acme.sh --issue -d example.com --standalone
systemctl start nginx

8. 切换 CA

8.1. 切换到 Let’s Encrypt

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

8.2. 切换到 ZeroSSL

acme.sh --set-default-ca --server zerossl
acme.sh --register-account -m my@example.com

9. 卸载 acme.sh

acme.sh --uninstall
rm -rf ~/.acme.sh/

10. 总结

  • acme.sh 是一个轻量级 ACME 客户端,适用于 Let’s Encrypt 和 ZeroSSL 证书。
  • 支持 Webroot、Standalone、DNS API 验证方式。
  • 证书默认存储在 ~/.acme.sh/ 目录,需要手动安装到 Web 服务器。
  • 自动续期,并提供详细的错误日志。
  • 可切换 CA,避免 Let’s Encrypt 速率限制。
分享一个微信朋友圈点赞秒赞软件,无需下载一秒几千赞 关于HP打印机在WIN7上打印窗口无响应的解决办法
biu biu biu
Linux 设置环境变量 wo mic手机秒变电脑麦克风,解决你台式电脑没有麦克风的尴尬 如何在Linux上安装和配置Syncthing,实现文件同步 关于小程序上canvas移动卡顿的解决方法 hi3798mv100编译ch341串口驱动