Let's Encrypt 如何将域名添加到现有证书中

158

我只是想将域名test.example.com添加到已有的证书example.com中。如何向现有证书添加域名并替换旧证书?

我尝试了以下几个命令

./letsencrypt-auto certonly --cert-path /etc/letsencrypt/archive/example.com --expand -d test.example.com

./letsencrypt-auto certonly -d example.com --expand -d test.example.com

结果:两者都在新文件夹test.example.com-0001中创建了全新的证书

./letsencrypt-auto certonly --renew-by-default  --expand -d test.example.com

结果:错误,文件夹 test.example.com 已存在。

./letsencrypt-auto renew --expand -d orange.fidka.com

结果:错误,只有在我的证书过期时才能进行更新。


2
这个问题已经在Super User上重新开放了:https://superuser.com/questions/1432541/letsencrypt-certbot-add-domain-to-existing-certificate - Mike Godin
3
对于现在查看此问题的任何人:我建议查看 superuser 上的答案。它使用 certbot --expand,我认为更接近此问题所询问的内容。 - Jesse Reza Khorasanee
6个回答

164

您需要指定所有名称,包括已经注册的名称。

我最初使用以下命令来注册一些证书:

/opt/certbot/certbot-auto certonly --webroot --agree-tos -w /srv/www/letsencrypt/ \
--email me@example.com \
--expand -d example.com,www.example.com

...刚刚我成功地使用了以下命令来扩展我的注册以包括一个新的子域名作为SAN:

/opt/certbot/certbot-auto certonly --webroot --agree-tos -w /srv/www/letsencrypt/ \
--expand -d example.com,www.example.com,click.example.com

根据文档

 

--expand "如果现有证书涵盖请求名称的某个子集,则始终扩展并用附加名称替换它。"

如果您正在运行nginx,请不要忘记重新启动服务器以加载新证书。


3
命令略有变化,现在是 certbot-auto certonly -a webroot ... - tsusanka
1
它适用于独立插件吗? - hjl
当我使用上述代码时,它会自动创建一个新的证书,并在结尾处添加“-001”。 - KhoPhi
在生产环境上运行它,扩展似乎不需要任何可见的停机时间。我使用了certbot-auto。 - Ray Foss
@simon-hampel 当 SSL 证书被扩展时,是否会为列表中定义的所有域名延长到期日期。 - Ersin Demirtas
显示剩余3条评论

53

在Ubuntu上使用Apache插件实现Apache:

sudo certbot certonly --cert-name example.com -d m.example.com,www.m.example.com

上述命令在Certbot用户指南中关于更改证书域名的章节中有生动的解释。请注意,更改证书域名的命令也适用于添加新域名。 编辑 如果运行上述命令出现以下错误信息:

Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA.

请按照Let's Encrypt社区的说明进行操作。

7
如果你只是在现有的内容上添加,可能会在文档中提到需要再次添加现有域名,否则它将被删除。 - Rob
1
他们还有一个--expand选项,你最初认为它允许你添加现有域名,但实际上并不是这样(摊手)。我真的不喜欢他们的选项或文档。 - adrianTNT

44

这是我注册域名的方法:

sudo letsencrypt --apache -d mydomain.com

然后可以使用相同的命令,加上额外的域名并按照说明操作:

sudo letsencrypt --apache -d mydomain.com,x.mydomain.com,y.mydomain.com

3
我刚刚用 ./certbot-auto 替换了 letsencrypt,它能够正常工作!命令 ./certbot-auto --nginx -d domain1.com,domain2.com 会询问是否要扩展现有证书并完成任务。 - George
1
谢谢。这节省了我的时间。我运行 ./letsencrypt-auto --debug -d new-domain.com -d new-alias.com - Nguyễn Văn Vinh

5
我使用--cert-name--expand选项,为一个域名和多个子域名设置了SSL证书。
请参见官方的certbot-auto文档:https://certbot.eff.org/docs/using.html 示例:
certbot-auto certonly --cert-name mydomain.com.br \
--renew-by-default -a webroot -n --expand \
--webroot-path=/usr/share/nginx/html \
-d mydomain.com.br \
-d www.mydomain.com.br \
-d aaa1.com.br \
-d aaa2.com.br \
-d aaa3.com.br

5

您可以通过再次运行 ./certbot-auto certonly 来替换证书。

如果您尝试为一个已经被现有证书覆盖的域生成证书,您将会收到以下提示信息:

-------------------------------------------------------------------------------
You have an existing certificate that contains a portion of the domains you
requested (ref: /etc/letsencrypt/renewal/<domain>.conf)

It contains these names: <domain>

You requested these names for the new certificate: <domain>,
<the domain you want to add to the cert>.

Do you want to expand and replace this existing certificate with the new
certificate?
-------------------------------------------------------------------------------

只需选择展开并替换它。


4
这对我很有帮助。
 sudo letsencrypt certonly -a webroot --webroot-path=/var/www/html -d
 domain.com -d www.domain.com

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