下载acme.sh
官方仓库及文档:https://github.com/acmesh-official/acme.sh
● 自动安装
# curl和wget任选其一下载安装
curl https://get.acme.sh | sh -s email=自己的邮箱
wget -O - https://get.acme.sh | sh -s email=自己的邮箱
● 手动安装
如果下载不下来,直接访问访问github仓库,将acme.sh复制到本地,执行以下命令安装。
sh acme.sh --install -m "自己的邮箱"
● 环境变量问题
安装好以后正常情况下可以直接使用acme.sh --xxx
的方式执行命令生成证书了,如果提示找不到acme.sh
, 手动加载下环境变量即可。
# 默认shell为bash执行
source ~/.bashrc
# 默认shell为zsh执行
source ~/.zshrc
签发证书
acme默认使用zeroSSL签发,也可以修改为letsencrypt
acme.sh --set-default-ca --server letsencrypt
- 开始签发
● 由于我的阿里云子账户没有权限创建API秘钥,这里我选择使用手动添加DNS的模式去生成证书
acme.sh --issue -d dev.xxx.cloud --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please
● 输出如下:
(base) ☁ ~ acme.sh --issue -d dev.xxx.cloud --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please
[2025年 8月 1日 星期五 11时23分42秒 CST] Using CA: https://acme-v02.api.letsencrypt.org/directory
[2025年 8月 1日 星期五 11时23分42秒 CST] Account key creation OK.
[2025年 8月 1日 星期五 11时23分42秒 CST] Registering account: https://acme-v02.api.letsencrypt.org/directory
[2025年 8月 1日 星期五 11时23分45秒 CST] Registered
[2025年 8月 1日 星期五 11时23分45秒 CST] ACCOUNT_THUMBPRINT='S3VKY1jHitM9fPvJvpSNEY_aeMWKl_4ioJnXqvse12c'
[2025年 8月 1日 星期五 11时23分45秒 CST] Single domain='dev.xxx.cloud'
[2025年 8月 1日 星期五 11时23分48秒 CST] Getting webroot for domain='dev.xxx.cloud'
[2025年 8月 1日 星期五 11时23分48秒 CST] Add the following TXT record:
[2025年 8月 1日 星期五 11时23分48秒 CST] Domain: '_acme-challenge.dev.xxx.cloud'
[2025年 8月 1日 星期五 11时23分48秒 CST] TXT value: 'oSLft65WsXWHfy9bnesxxxxxxxY'
[2025年 8月 1日 星期五 11时23分48秒 CST] Please make sure to prepend '_acme-challenge.' to your domain
[2025年 8月 1日 星期五 11时23分48秒 CST] so that the resulting subdomain is: _acme-challenge.dev.xxx.cloud
[2025年 8月 1日 星期五 11时23分48秒 CST] Please add the TXT records to the domains, and re-run with --renew.
[2025年 8月 1日 星期五 11时23分48秒 CST] Please add '--debug' or '--log' to see more information.
[2025年 8月 1日 星期五 11时23分48秒 CST] See: https://github.com/acmesh-official/acme.sh/wiki/How-to-debug-acme.sh
- 添加解析记录并验证
● 根据提示将TXT的域名解析记录添加到对应域名解析即可.
● 再次执行命令进行DNS记录验证
acme.sh --renew -d dev.xxx.cloud --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please
● 输出如下
(base) ☁ ~ acme.sh --renew -d dev.xxx.cloud --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please
[2025年 8月 1日 星期五 11时25分26秒 CST] The domain 'dev.xxx.cloud' seems to already have an ECC cert, let's use it.
[2025年 8月 1日 星期五 11时25分26秒 CST] Renewing: 'dev.xxx.cloud'
[2025年 8月 1日 星期五 11时25分26秒 CST] Renewing using Le_API=https://acme-v02.api.letsencrypt.org/directory
[2025年 8月 1日 星期五 11时25分28秒 CST] Using CA: https://acme-v02.api.letsencrypt.org/directory
[2025年 8月 1日 星期五 11时25分28秒 CST] Single domain='dev.xxx.cloud'
[2025年 8月 1日 星期五 11时25分28秒 CST] Verifying: dev.xxx.cloud
[2025年 8月 1日 星期五 11时25分31秒 CST] Pending. The CA is processing your order, please wait. (1/30)
[2025年 8月 1日 星期五 11时25分35秒 CST] Success
[2025年 8月 1日 星期五 11时25分35秒 CST] Verification finished, beginning signing.
[2025年 8月 1日 星期五 11时25分36秒 CST] Let's finalize the order.
[2025年 8月 1日 星期五 11时25分36秒 CST] Le_OrderFinalize='https://acme-v02.api.letsencrypt.org/acme/finalize/2566534311/413119374021'
[2025年 8月 1日 星期五 11时25分38秒 CST] Downloading cert.
[2025年 8月 1日 星期五 11时25分38秒 CST] Le_LinkCert='https://acme-v02.api.letsencrypt.org/acme/cert/05821debd1b2489654e2310c993d4582d8c3'
[2025年 8月 1日 星期五 11时25分39秒 CST] Cert success.
-----BEGIN CERTIFICATE-----
MIIDojCCAyigAwIBAgISBYId69GySJZU4jEMmT1FgtjDMAoGCCqGSM49BAMDMDIx
CzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQDEwJF
NjAeFw0yNTA4MDExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxBAMTGmRl
di5vc3MtdXBsb2FkLnF1aHVvLmNsb3VkMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD
QgAE1A7xFkoB4kFSIScrUwhWQGYF+Gr3IsK3yJb8zYDB/TvC5fzRecA0oRmjTMqT
1XWh4HinAMz/zxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/wQEAwIHgDAdBgNV
HSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4E
FgQUi8Ed2flmewWcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxUkydGmAOpUWiOmNbE
QkjbI79YlNIwMgYIKwYBBQUHAQEEJjAkMCIGCCsGAQUFBzAChhZodHRwOi8vZTYu
aS5sZW5jci5vxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxkLnF1aHVvLmNs
b3VkMBMGA1UdIAQMMAowCAYGZ4EMAQIBMC0GA1UdHwQmMCQwIqAgoB6GHGh0dHA6
Ly9lNi5jLmxlbmNyLm9yZy82OC5jcmwwggEFBgorBgEEAdZ5AgQCBIH2BIHzAPEA
dwAaBP9J0FQdQK/2oMO/8djEZy9O7O4jQGiYaxdALtyJfQAAAZhjqfVGAAAEAwBI
MEYCIQCXQXszDpeC3SrZjWvkDgWtqr+6v8ck31cBcgBuizY1sAIhAIA5Uo6LpY10
v5wHHbGc4oaL5LsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxRYF55Uy+sef+D0cUN/b
ADoUEnYKLKy7yCoAAAGYY6n1XAAABAMARzBFAiBha8xrE86yFuQeNDCEB8b7hWBV
6c7O7g1BGFFD7G135AIhAOcLqgeqXNI+LBRklJDPD73j7ejSX4LRyQ2qHoecx2iW
MAoGCCqGSMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxQsi
z7EK3rOdeoTt3n7km9puaPGZkAIxALPP5yn5yN2Jho/a2ZKx9N4P0uUNHGKUuJe0
5Tzz3lcJO4nSeK481WhLiAWqX8Z+NA==
-----END CERTIFICATE-----
[2025年 8月 1日 星期五 11时25分39秒 CST] Your cert is in: /Users/xxxx/.acme.sh/dev.xxx.cloud_ecc/dev.xxx.cloud.cer
[2025年 8月 1日 星期五 11时25分39秒 CST] Your cert key is in: /Users/xxxx/.acme.sh/dev.xxx.cloud_ecc/dev.xxx.cloud.key
[2025年 8月 1日 星期五 11时25分39秒 CST] The intermediate CA cert is in: /Users/xxxx/.acme.sh/dev.xxx.cloud_ecc/ca.cer
[2025年 8月 1日 星期五 11时25分39秒 CST] And the full-chain cert is in: /Users/xxxx/.acme.sh/dev.xxx.cloud_ecc/fullchain.cer
- 提取文件部署证书
● 根据输出提示可了解到生成的证书存放在用户目录下的.acme.sh/dev.xxx.cloud_ecc
目录下 。
(base) ☁ dev.xxx.cloud_ecc ll
total 56
-rw-r--r--@ 1 xxxx staff 1.5K 8 1 11:25 ca.cer
-rw-r--r--@ 1 xxxx staff 1.3K 8 1 11:25 dev.xxx.cloud.cer
-rw-r--r--@ 1 xxxx staff 618B 8 1 11:25 dev.xxx.cloud.conf
-rw-r--r--@ 1 xxxx staff 497B 8 1 11:25 dev.xxx.cloud.csr
-rw-r--r--@ 1 xxxx staff 199B 8 1 11:25 dev.xxx.cloud.csr.conf
-rw-------@ 1 xxxx staff 227B 8 1 11:19 dev.xxx.cloud.key
-rw-r--r--@ 1 xxxx staff 2.8K 8 1 11:25 fullchain.cer
● 此时只需要将证书链文件和私钥部署到对应服务器即可。
......
ssl_certificate /etc/nginx/ssl/fullchain.cer; # 完整证书链
ssl_certificate_key /etc/nginx/ssl/dev.xxx.cloud.key; # 证书私钥
......