侧边栏壁纸
博主头像
一杯苦咖啡 博主等级

越是宣传的,越是有坑等你填补,越是禁止的,越是不想让你分享的,做一个能独立思考的人

  • 累计撰写 31 篇文章
  • 累计创建 3 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

使用ACME申请SSL证书

Administrator
2024-04-28 / 0 评论 / 0 点赞 / 31 阅读 / 0 字 / 正在检测是否收录...

1. 如何安装

1.在线安装

检查这个项目:https://github.com/acmesh-official/get.acme.sh

curl https://get.acme.sh | sh -s email=my@example.com

或者:

wget -O -  https://get.acme.sh | sh -s email=my@example.com

2. 或者,从 git 安装

克隆该项目并启动安装:

git clone https://github.com/acmesh-official/acme.sh.git
cd ./acme.sh
./acme.sh --install -m my@example.com

那么你don't have to be root,虽然it is recommended

高级安装:https://github.com/acmesh-official/acme.sh/wiki/How-to-install

安装程序将执行 3 个操作:

  1. 创建并复制acme.sh到您的主目录 ( $HOME): ~/.acme.sh/。所有证书也将放置在此文件夹中。

  2. 创建别名:acme.sh=~/.acme.sh/acme.sh.

  3. 创建每日 cron 作业来检查并更新证书(如果需要)。

cron 条目示例:

0 0 * * * "/home/user/.acme.sh"/acme.sh --cron --home "/home/user/.acme.sh" > /dev/null

安装完成后,必须关闭当前终端并重新打开才能使别名生效。

好的,您现在可以颁发证书了。

显示帮助消息:

root@v1:~# acme.sh -h

2.只需颁发证书

示例 1:单个域。

acme.sh --issue -d example.com -w /home/wwwroot/example.com

或者:

acme.sh --issue -d example.com -w /home/username/public_html

或者:

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

示例 2:同一证书中的多个域。

acme.sh --issue -d example.com -d www.example.com -d cp.example.com -w /home/wwwroot/example.com

参数/home/wwwroot/example.comor/home/username/public_html/var/www/html是您托管网站文件的 Web 根文件夹。你必须write access这个文件夹。

第二个参数“example.com”是您要为其颁发证书的主域。您必须至少拥有一个域。

您必须将所有域指向并绑定到同一个 webroot 目录:/home/wwwroot/example.com

证书将被放置在~/.acme.sh/example.com/

证书将每60天自动更新一次。

更多示例:https://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

3. 将证书安装到 Apache/Nginx 等。

生成证书后,您可能希望将证书安装/复制到您的 Apache/Nginx 或其他服务器。您必须使用此命令将证书复制到目标文件,请勿使用~/.acme.sh/文件夹中的证书文件,它们仅供内部使用,文件夹结构将来可能会更改。

阿帕奇示例:

acme.sh --install-cert -d example.com \
--cert-file      /path/to/certfile/in/apache/cert.pem  \
--key-file       /path/to/keyfile/in/apache/key.pem  \
--fullchain-file /path/to/fullchain/certfile/apache/fullchain.pem \
--reloadcmd     "service apache2 force-reload"

Nginx示例:

acme.sh --install-cert -d example.com \
--key-file       /path/to/keyfile/in/nginx/key.pem  \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd     "service nginx force-reload"

仅域是必需的,所有其他参数都是可选的。

现有文件的所有权和权限信息将被保留。您可以预先创建文件来定义所有权和权限。

将证书/密钥安装/复制到生产 Apache 或 Nginx 路径。

默认情况下,证书每60天更新一次(可配置)。更新证书后,Apache/Nginx 服务将通过以下命令自动重新加载:service apache2 force-reloadservice nginx force-reload

请注意:reloadcmd 非常重要。证书可以自动续订,但是,如果没有正确的“reloadcmd”,证书可能无法刷新到您的服务器(如 nginx 或 apache),那么您的网站将无法在 60 天内显示续订的证书。

4. 使用独立服务器颁发证书

(要求您是 root/sudoer 或具有侦听端口 80 (TCP) 的权限)

端口80(TCP)必须可以自由侦听,否则系统会提示您释放它并重试。

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

更多示例:https://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

5.使用Standalone ssl服务器颁发证书

(要求您是 root/sudoer 或有权侦听端口 443 (TCP))

端口443(TCP)必须可以自由侦听,否则系统会提示您释放它并重试。

acme.sh --issue --alpn -d example.com -d www.example.com -d cp.example.com

更多示例:https://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

6.使用Apache模式

(要求您是 root/sudoer,因为需要与 Apache 服务器交互)

如果您正在运行 Web 服务器,建议使用Webroot mode.

特别是,如果您正在运行 Apache 服务器,则可以使用 Apache 模式。此模式不会将任何文件写入您的 Web 根文件夹。

只需将字符串“apache”设置为第二个参数,它就会自动强制使用 apache 插件。

acme.sh --issue --apache -d example.com -d www.example.com -d cp.example.com

此 apache 模式仅颁发证书,它不会更改您的 apache 配置文件。您需要配置网站配置文件才能自行使用证书。我们不想弄乱您的 apache 服务器,别担心。

更多示例:https://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

7.使用Nginx模式

(需要你是 root/sudoer,因为它需要与 Nginx 服务器交互)

如果您正在运行 Web 服务器,建议使用Webroot mode.

特别是,如果您正在运行 nginx 服务器,则可以使用 nginx 模式。此模式不会将任何文件写入您的 Web 根文件夹。

只需将字符串“nginx”设置为第二个参数即可。

它会自动配置 nginx 服务器来验证域,然后将 nginx 配置恢复到原始版本。

所以,配置没有改变。

acme.sh --issue --nginx -d example.com -d www.example.com -d cp.example.com

这种nginx模式只是颁发证书,它不会改变你的nginx配置文件。您需要配置网站配置文件才能自行使用证书。我们不想弄乱您的 nginx 服务器,不用担心。

更多示例:https://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

8. 自动 DNS API 集成

如果您的 DNS 提供商支持 API 访问,我们可以使用该 API 自动颁发证书。

您无需手动执行任何操作!

目前 acme.sh 支持大多数 dns 提供商:

https://github.com/acmesh-official/acme.sh/wiki/dnsapi

9.使用DNS手动模式:

首先参见:https://github.com/acmesh-official/acme.sh/wiki/dns-manual-mode

如果您的dns提供商不支持任何api访问,您可以手动添加txt记录。

acme.sh --issue --dns -d example.com -d www.example.com -d cp.example.com

您应该得到如下输出:

Add the following txt record:
Domain:_acme-challenge.example.com
Txt value:9ihDbjYfTExAYeDs4DBUeuTo18KBzwvTEjUnSwd32-c

Add the following txt record:
Domain:_acme-challenge.www.example.com
Txt value:9ihDbjxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Please add those txt records to the domains. Waiting for the dns to take effect.

然后用renew参数重新运行:

acme.sh --renew -d example.com

好的,完成了。

注意,这是dns手动模式,不能自动更新。当您续订证书时,您必须手动向您的域添加新的 txt 记录。

请改用dns api模式。

10.颁发ECC证书

只需设置keylength带有前缀的参数即可ec-

例如:

单域ECC证书

acme.sh --issue -w /home/wwwroot/example.com -d example.com --keylength ec-256

SAN多域ECC证书

acme.sh --issue -w /home/wwwroot/example.com -d example.com -d www.example.com --keylength ec-256

请看keylength上面的参数。

有效值为:

  1. ec-256(prime256v1,“ECDSA P-256”,这是默认密钥类型)

  2. ec-384(secp384r1,“ECDSA P-384”)

  3. ec-521(secp521r1,“ECDSA P-521”,Let's Encrypt 尚不支持。)

  4. 2048(RSA2048)

  5. 3072(RSA3072)

  6. 4096(RSA4096)

11. 颁发通配符证书

很简单,只要给出一个通配符域作为-d参数即可。

acme.sh  --issue -d example.com  -d '*.example.com'  --dns dns_cf

12. 如何更新证书

不,您不需要手动续订证书。所有证书将每60天自动更新一次。

但是,您也可以强制续订证书:

acme.sh --renew -d example.com --force

或者,对于 ECC 证书:

acme.sh --renew -d example.com --force --ecc

13. 如何停止证书续订

要停止更新证书,您可以执行以下命令从更新列表中删除证书:

acme.sh --remove -d example.com [--ecc]

证书/密钥文件不会从磁盘中删除。

~/.acme.sh/example.com您可以自行删除相应的目录(例如)。

14. 如何升级acme.sh

acme.sh 正在不断开发中,因此强烈建议使用最新的代码。

您可以将 acme.sh 更新为最新代码:

acme.sh --upgrade

您还可以启用自动升级:

acme.sh --upgrade --auto-upgrade

然后acme.sh将自动保持最新。

禁用自动升级:

acme.sh --upgrade --auto-upgrade 0


0

评论区