如何使用Certbot仅更新一个域名?

114

我有多个域名和多个证书:

$ ll /etc/letsencrypt/live/
> domain1.com
> domain2.com
> domain3.com
> ...

我只需要更新 domain1.com 的证书,但命令 certbot renew 会为所有域名更新证书。如何显式地更新特定证书?

4个回答

171

使用renew命令和--cert-name选项来更新单个证书。

(certonly为一个或多个域创建证书,如已存在则替换原证书)。

示例

certbot renew --cert-name domain1.com --dry-run

要实际更新,请删除--dry-run


Cert-name != Domain name

请注意,提供给--cert-name选项的值是证书名称(不是域名),可以使用以下内容找到:

certbot certificates

返回像这样的列表

-------------------------------------------------------------------------------
Found the following certs:
  Certificate Name: myfundomains.com
    Domains: myfundomains.com
    Expiry Date: 2018-05-04 04:28:05+00:00 (VALID: 67 days)
    Certificate Path: /etc/letsencrypt/live/myfundomains.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/myfundomains.com/privkey.pem
  Certificate Name: ask.myfundomain.com
    Domains: ask.myfundomain.com
    Expiry Date: 2018-03-13 18:59:40+00:00 (VALID: 16 days)
    Certificate Path: /etc/letsencrypt/live/ask.myfundomain.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/ask.myfundomain.com/privkey.pem
  Certificate Name: forums.myfundomain.com
    Domains: forums.myfundomain.com forum.myfundomain.com
    Expiry Date: 2018-04-11 16:39:18+00:00 (VALID: 45 days)
    Certificate Path: /etc/letsencrypt/live/forums.myfundomain.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/forums.myfundomain.com/privkey.pem
-------------------------------------------------------------------------------

请注意第三个证书名称(forums.myfundomain.com)包含多个域名

  • forums.myfundomains.com
  • forum.myfundomains.com

重新启动Apache / nginx

-------------------------------------------------------------------------------
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/ask.myfundomain.com/fullchain.pem
-------------------------------------------------------------------------------

记得重新启动你的 Web 服务器以使用新的证书。


1
是的,当您使用自定义构建的nginx时,这种方法非常有用。 - anhtran
1
谢谢!以下是在(例如)www.domain.nl和domain.nl上运行的命令,只需一个命令即可:certbot renew -n --cert-name www.domain.nl --force-renewal。 - Ramon Fincken
service nginx reload 就可以了 - 不需要重新启动。 - cybernet2u

115

你可以使用以下命令(适用于Apache服务器):

certbot --apache certonly -n -d domain1.com
  • --apache 指定使用 Apache 服务器,使用 --nginx 标志指定 Nginx 服务器
  • -n 选项在不提示的情况下执行命令
  • -d domain1.com 仅为 domain1.com 执行

您可以使用 --dry-run 进行测试,并且您可以像使用 certbot renew 一样使用 --pre-hook--post-hook

来源:https://certbot.eff.org/docs/using.html#renewing-certificates


5
你的回答帮助了我解决了关于nginx的问题。请也提供一下nginx服务器的相关内容。--nginx - Dslayer

1

您可以在Nginx服务器上使用以下命令:

  1. 停止Nginx服务器

    sudo systemctl stop nginx

  2. 更新Certbot

    sudo certbot certonly --force-renew -d domain1.com

  3. 启动Nginx服务器

    sudo systemctl start nginx

  4. 检查当前证书

    sudo certbot certificates

结果:

找到以下证书:证书名称:domain1.com 序列号:4564f55f3fe993964f8bbc65249a7ed4c91 密钥类型:RSA 域名:domain1.com 到期日期:2022-12-19 01:34:25+00:00(有效期89天) 证书路径:/etc/letsencrypt/live/domain1.com/fullchain.pem 私钥路径:/etc/letsencrypt/live/domain1.com/privkey.pem


0
添加新的域名 手动编写-le-ssl文件并运行以下命令
 sudo certbot -d domainname --expand

由于Ubuntu 22中的自动SSL文件创建不支持我,所以...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接