【问题标题】:Certbot www and non-www with --non-interactive = vhost ambiguityCertbot www 和 non-www with --non-interactive = vhost ambiguity
【发布时间】:2017-11-10 19:16:09
【问题描述】:

我正在尝试为单个域生成证书,但同时适用于 www 和非 www。

这就是我现在的运行方式:

certbot --apache -n -d domain.tld -d www.domain.tld --agree-tos --email mail@domain.com --redirect

但我得到以下信息:

遇到 vhost 歧义,但无法请求用户指导 非交互模式。目前 Certbot 需要每个虚拟主机都在其 自己的 conf 文件,并且可能需要明确标记虚拟主机 ServerName 或 ServerAlias 目录。

所以我必须在没有 -n(--non-interactive) 的情况下运行它并选择正确的 vhost 文件。

有什么方法可以在没有任何提示的情况下为 www 和非 www 生成证书?

【问题讨论】:

    标签: ssl ssl-certificate lets-encrypt certbot


    【解决方案1】:

    有许多可能导致此错误消息。这表明您的虚拟主机配置有问题。 但总结一下最突出的原因:

    • 您在一个 .conf 文件中有多个 <VirtualHost >
    • 您有多个 .conf 文件,例如对于端口 80 和 443,它们不具有完全相同的 ServerName 和/或 ServerAlias 属性
    • 您根本没有在 .conf 文件中指定任何 ServerName
    • domain.tld 和/或 www.domain.tld 未在您的 .conf 文件中指定

    此外,我建议您使用 --dry-run 选项运行 certbot 进行调试。此外,对于 cron 中的自动更新,有 /etc/certbot-auto renew
    因此,您可以尝试/etc/certbot-auto renew --dry-run 来获取配置文件中指定的所有域。 提醒:请不要忘记在每次更改 vhost 配置后使用 service apache2 restart 或类似名称重新启动或重新加载 apache

    【讨论】:

      【解决方案2】:

      certbot 需要您正确配置虚拟主机。您需要编辑 apache2 配置文件,以便 www.domain.comdomain.com 的别名

      [你需要根据你的服务器设置编辑相应的配置文件]

      例如我的服务器是这样的

      /etc/apache2/sites-available/domain.com.conf

      <VirtualHost *:80>
          ServerAdmin webmaster@localhost
          ServerName domain.com
          ServerAlias www.domain.com
          DocumentRoot /var/www/domain.com
          ErrorLog /error.log
          CustomLog /access.log combined
      </VirtualHost>
      

      然后再次运行 certbot

      sudo certbot  --noninteractive --agree-tos  --no-eff-email  --cert-name domain.com --apache --no-redirect  -d domain.com -d www.domain.com -m siteadminsemail@gmail.com
      

      我希望它对某人有所帮助,它困扰了我 2 天,我什至因为尝试使用 certbot 太多次而被letsencrypt暂时禁止:(

      【讨论】:

        【解决方案3】:

        有什么方法可以在没有任何提示的情况下为 www 和非 www 生成证书?

        不,目前有not。如果您有复杂的虚拟主机,我不相信 certbot 可以正确管理它们。这只是感觉不可靠,事实证明,至少目前它在实践中是不可靠的。

        关于 certbot 的 apache 模块可以可靠地对您的 vhost 做的唯一事情是在 single --domain 案例中的全新安装上安装默认 SSL vhost。对于其他任何事情,请使用 certonly 选项,然后放入链接到生成的证书的虚拟主机,这很容易。证书的路径可以由 first 域参数的值或--cert-name 参数指定的值可靠地确定。所以:

        certbot certonly --apache -n --domains domain.tld,www.domain.tld --agree-tos --email mail@domain.com
        

        然后放入链接到证书路径的虚拟主机。示例默认 SSL 虚拟主机 000-default-ssl.conf

        <IfModule mod_ssl.c>
          <VirtualHost *:443>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
            # LogLevel info ssl:warn
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
            # ServerName not required for default.
            SSLCertificateFile /etc/letsencrypt/live/domain.tld/fullchain.pem
            SSLCertificateKeyFile /etc/letsencrypt/live/domain.tld/privkey.pem
            Include /etc/letsencrypt/options-ssl-apache.conf
          </VirtualHost>
        </IfModule>
        

        然后重新加载:

        a2ensite 000-default-ssl.conf
        service apache2 reload
        

        【讨论】:

          猜你喜欢
          • 2020-03-11
          • 2020-03-18
          • 2017-02-18
          • 1970-01-01
          • 2012-06-09
          • 2019-10-26
          • 2020-11-28
          • 2018-07-03
          相关资源
          最近更新 更多