“Acme.sh 使用”的版本间差异
跳到导航
跳到搜索
(建立内容为“category:网络工具 == 关于 == 通过 acme.sh 脚本,可以申请、自动更新证书。 支持的证书: * ZeroSSL.com CA(default) * Letsencr…”的新页面) |
|||
第91行: | 第91行: | ||
acme.sh --issue --dns dns_cf -d <example.com> [-d <example.com>] | acme.sh --issue --dns dns_cf -d <example.com> [-d <example.com>] | ||
</syntaxhighlight> | </syntaxhighlight> | ||
#* CloudFlare API Key 创建地址:[https://dash.cloudflare.com/profile https://dash.cloudflare.com/profile] | #* CloudFlare API Key 创建地址:[https://dash.cloudflare.com/profile https://dash.cloudflare.com/profile]。 | ||
#* | #* 配置步骤,1、先配置 DNS 解析,2、生成 CloudFlare API Key: | ||
#*# | #*# 在 CloudFlare 添加站点(根域名); | ||
#*# 在“DNS”项,添加记录(“类型”:A;“名称”:子域名的一级域名;“内容”:服务器IP); | #*# 在“DNS”项,添加记录(“类型”:A;“名称”:子域名的一级域名;“内容”:服务器IP); | ||
#*# | #*# 根据提示,修改域名供应商的 DNS 地址(在“DNS修改”将其 DNS 指定为 CloudFlare 的 DNS 地址); | ||
#*# 在 CloudFlare 将 SSL/TLS 更改为“完全”(Full); | #*# 在 CloudFlare 将 SSL/TLS 更改为“完全”(Full); | ||
#*# 验证配置(ping 一下该域名,得到一个ip,查一查该ip是不是 CloudFlare 的地址) | #*# 验证配置(ping 一下该域名,得到一个ip,查一查该ip是不是 CloudFlare 的地址) | ||
#* <syntaxhighlight lang="bash" highlight=""> | |||
CloudFlare 可用于“'''DNS 解析'''”和“'''CDN 加速'''”。 | |||
(此处只用其 DNS 解析的功能,因为国外的 CDN 反而可能导致降速) | |||
(如果 ip 被锁,倒是可以考虑使用其 CDN 功能拯救一下 ip) | |||
</syntaxhighlight> | |||
2021年12月3日 (五) 07:18的版本
关于
通过 acme.sh 脚本,可以申请、自动更新证书。 支持的证书: * ZeroSSL.com CA(default) * Letsencrypt.org CA * BuyPass.com CA * SSL.com CA * Pebble strict Mode * Any other RFC8555-compliant CA acme.sh 项目(中文说明) (包括 Cloudflare、GoDaddy、Aliyun)
参考:
安装、更新
安装脚本
# 在线安装 curl https://get.acme.sh | sh # 或者 wget -O - https://get.acme.sh | sh # 通过 git 安装 git clone https://github.com/acmesh-official/acme.sh.git cd ./acme.sh ./acme.sh --install
- 安装位置:“~/.acme.sh/”(若 root 用户安装,即:“/root/.acme.sh”);
- 安装好后,会自动为你创建 cronjob(计划任务), 每天 0:00 点自动检测所有的证书, 如果快过期了, 需要更新, 则会自动更新证书。
- 查看已创建的 cronjob:
crontab -l
更新
# 升级 acme.sh 到最新版 : acme.sh --upgrade # 如果你不想手动升级, 可以开启自动升级: acme.sh --upgrade --auto-upgrade # 你也可以随时关闭自动更新: acme.sh --upgrade --auto-upgrade 0
证书生成
HTTP 认证方式
该方式 acme.sh 会在你的指定的网站根目录下自动生成一个文件,来验证域名所有权,然后自动完成验证并签发证书。
命令:
acme.sh --issue -d mydomain.com -d www.mydomain.com --webroot /home/wwwroot/mydomain.com/
- 完成后会自动删除验证文件,无需多余操作。
DNS认证方式(推荐)
这种方式不需要服务器和公网 IP,只需要 DNS 的解析记录即可完成验证,一般主流域名服务商都提供 API 接口。 目前 acme.sh 支持大多数 dns 提供商(包括主流的 CloudFlare、DNSPod、Aliyun、Amazon Route53 在内的多达 131 个的域名 API)
- 给 GoDaddy 自动颁发证书:
#(替换 GD_Key 为自己的) export GD_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" #(替换 GD_Secret 为自己的) export GD_Secret="asdfsdafdsfdsfdsfdsfdsafd" #(<example.com> 为自己的域名) acme.sh --issue --dns dns_gd -d <example.com> [-d <example.com>]
- GoDaddy API Key 创建地址:https://developer.godaddy.com/keys/
- 给 CloudFlare 自动颁发证书:
#(替换 CF_Key 为自己的) export CF_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" #(替换 CF_Email 为自己的 GoDaddy 登录邮箱) export CF_Email="xxxx@sss.com" #(<example.com> 为自己的域名) acme.sh --issue --dns dns_cf -d <example.com> [-d <example.com>]
- CloudFlare API Key 创建地址:https://dash.cloudflare.com/profile。
- 配置步骤,1、先配置 DNS 解析,2、生成 CloudFlare API Key:
- 在 CloudFlare 添加站点(根域名);
- 在“DNS”项,添加记录(“类型”:A;“名称”:子域名的一级域名;“内容”:服务器IP);
- 根据提示,修改域名供应商的 DNS 地址(在“DNS修改”将其 DNS 指定为 CloudFlare 的 DNS 地址);
- 在 CloudFlare 将 SSL/TLS 更改为“完全”(Full);
- 验证配置(ping 一下该域名,得到一个ip,查一查该ip是不是 CloudFlare 的地址)
CloudFlare 可用于“'''DNS 解析'''”和“'''CDN 加速'''”。 (此处只用其 DNS 解析的功能,因为国外的 CDN 反而可能导致降速) (如果 ip 被锁,倒是可以考虑使用其 CDN 功能拯救一下 ip)
关于默认 CA
执行时,提示:
[root@newjersey ~]# acme.sh --issue --dns dns_cf -d <example.com> [Tue Nov 30 23:12:51 UTC 2021] Using CA: https://acme.zerossl.com/v2/DV90 [Tue Nov 30 23:12:51 UTC 2021] Create account key ok. [Tue Nov 30 23:12:51 UTC 2021] No EAB credentials found for ZeroSSL, let's get one [Tue Nov 30 23:12:51 UTC 2021] acme.sh is using ZeroSSL as default CA now. [Tue Nov 30 23:12:51 UTC 2021] Please update your account with an email address first. [Tue Nov 30 23:12:51 UTC 2021] acme.sh --register-account -m my@example.com [Tue Nov 30 23:12:51 UTC 2021] See: https://github.com/acmesh-official/acme.sh/wiki/ZeroSSL.com-CA [Tue Nov 30 23:12:51 UTC 2021] Please add '--debug' or '--log' to check more details. [Tue Nov 30 23:12:51 UTC 2021] See: https://github.com/acmesh-official/acme.sh/wiki/How-to-debug-acme.sh
- 即,acme.sh 现在(从2021年8月1日起)默认 CA 换成了 ZeroSSL。
所以如果需要使用其他 CA:(两种方式)
- 签发证书时指定 CA:
acme.sh --issue --dns dns_cf -d <example.com> --server letsencrypt
- 直接更改默认 CA:
acme.sh --set-default-ca --server letsencrypt
- 以后就算版本升级也将一直默认使用指定的 CA。
证书安装
默认生成的证书都放在安装目录下:~/.acme.sh/
建议使用 --install-cert 命令指定目标位置,将证书文件复制到相应的位置:
acme.sh --install-cert -d mydomain.com \ --key-file /path/to/ssl/private.key \ --fullchain-file /path/to/ssl/fullchain.pem \ --reloadcmd "service nginx force-reload"
- 这里指定的所有参数都会被自动记录下来,并在将来证书自动更新以后,被再次自动调用,目前证书在60天以后会自动更新,无需任何操作。
证书删除
如果要撤销一个证书,使用:
acme.sh --list acme.sh --revoke -d mydomain.com
如果要删除一个证书,使用:
acme.sh --list acme.sh --remove -d mydomain.com
FAQ
“-bash: acme.sh: command not found”
如果“acme.sh”命令提示:“-bash: acme.sh: command not found”,则先执行以下命令:
source ~/.bashrc
再继续执行其他命令。