如何用acme.sh高效自动续签获取Let's Encrypt免费SSL证书?

摘要:acme.sh References acme.sh acme.sh 中文 WiKi 使用acme.sh免费申请HTTPS证书 备注 下列代码主要为方便记忆,并非可用。 安装 见 References#2 acme.sh 中文 WiKi c
acme.sh References acme.sh acme.sh 中文 WiKi 使用acme.sh免费申请HTTPS证书 备注 下列代码主要为方便记忆,并非可用。 安装 见 References#2 acme.sh 中文 WiKi curl https://get.acme.sh 可选 配置 Servers,默认 SSL server 是 zerossl,我用的是 LetsEncrypt.org。 --server <server_uri> ACME Directory Resource URI. (default: https://acme.zerossl.com/v2/DV90) See: https://github.com/acmesh-official/acme.sh/wiki/Server 代码: acme.sh --server LetsEncrypt.org 示例: # /bin/bash DOMAIN_NAME=$1 ROOT_DIR=$2 # 生成 RSA 证书: acme.sh --issue -d $DOMAIN_NAME -w $ROOT_DIR # 生成 ECC 证书: # PS: acme.sh 有三种验证方式可供选择: # 1. HTTP webroot 验证 # 2. standalone 验证 # 3. DNS 验证 # 假设您已经有一个运行中的 web 服务器并希望使用 HTTP webroot 验证,您需要指定 webroot 目录的路径。 # !!! 一定要找准 webroot 目录,否则执行 `--issue` 命令会失败 # 使用 acme.sh 签发证书。将 your_webroot 替换为实际的 webroot 目录路径,然后运行以下命令: acme.sh --issue -d $DOMAIN_NAME -d www.$DOMAIN_NAME -w $ROOT_DIR --keylength ec-256 # 查看已生成的证书 acme.sh --list # 将 ~/.acme.sh/$DOMAIN_NAME_ecc(我使用 ECC 证书所以有 ECC) 目录下内容复制到 nginx 配置目录下 # 见 References#1 [3. copy/安装 证书](https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E#3-copy%E5%AE%89%E8%A3%85-%E8%AF%81%E4%B9%A6) cp -r /root/.acme.sh/$DOMAIN_NAME_ecc/ /etc/nginx/ssl/$DOMAIN_NAME/ # 安装 RSA 证书 acme.sh --install-cert -d $DOMAIN_NAME \ --key-file /etc/nginx/ssl/$DOMAIN_NAME/$DOMAIN_NAME.rsa.key \ --fullchain-file /etc/nginx/ssl/$DOMAIN_NAME/$DOMAIN_NAME.rsa.crt \ --reloadcmd "systemctl reload nginx" # 安装 ECC 证书 # 使用 –installcert 命令,并指定目标位置,然后证书文件会被复制到相应的位置 acme.sh --install-cert -d $DOMAIN_NAME \ --key-file /etc/nginx/ssl/$DOMAIN_NAME/$DOMAIN_NAME.key \ --fullchain-file /etc/nginx/ssl/$DOMAIN_NAME/$DOMAIN_NAME.crt \ # –reloadcmd 参数用于让web服务器重新加载新的证书文件,例子中使用的是 nginx 服务器,您也可以定义成其它服务器。
阅读全文