修复 Let's Encrypt 与 www 一起工作

Fix so Let's Encrypt works with www

Firefox does not trust this site since it uses a certifcate which is not valid for www.example.com. Certificate is only valid for example.com.

Error code: SSL_ERROR_BAD_CERT_DOMAIN

我在 Ubuntu 16,Apache httpd 上使用 Let's Encrypt。

我如何添加它也适用于 www?我猜是 Apache 中的一些 conf?

找不到任何相关信息。

假设您已经安装了 certbot (docs for your version of Ubuntu and Apache), you should use the -d command line switch to list the domains you want the certificate to work for. From the docs:

 -d DOMAIN, --domains DOMAIN, --domain DOMAIN
                   Domain names to apply. For multiple domains you can
                   use multiple -d flags or enter a comma separated list
                   of domains as a parameter. The first domain provided
                   will be the subject CN of the certificate, and all
                   domains will be Subject Alternative Names on the
                   certificate. The first domain will also be used in
                   ...

如果你想做一个干燥的 运行 测试,使用 certonly--dry-run(你必须 运行 as rootsudo):

certbot certonly --dry-run -d www.example.com -d example.com

如果看起来一切正常,实际生成、安装和激活证书(注意这将重新启动 Apache):

certbot --apache -d www.example.com -d example.com

certbot 将为您对 Apache 配置进行必要的编辑。

如果您更愿意手动进行编辑,请使用 webroot 选项。 The docs for that option include an example of doing this for multiple domains, including example.com and www.example.com。从该示例中删除其他域以简化这种情况:

certbot certonly --webroot -w /var/www/example -d www.example.com -d example.com

您需要自己重新启动 Apache 才能在使用此选项时使用新证书。