【问题标题】:Apache 2.4.9 fails after enabling ssl module and setting up ssl certificate启用 ssl 模块并设置 ssl 证书后 Apache 2.4.9 失败
【发布时间】:2023-03-04 04:28:01
【问题描述】:

Apache 在尝试设置 ssl 证书后抛出以下错误:

[ssl:emerg] [pid 30907] AH02572: Failed to configure at least one certificate and key for localhost:443
[ssl:emerg] [pid 30907] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned
[ssl:emerg] [pid 30907] AH02312: Fatal error initialising mod_ssl, exiting.

我使用 MAC OS:Yosemite、PHP 5.5.20、Apache 2.4.9

并已按照以下步骤生成我的 ssl 证书 (http://www.akadia.com/services/ssh_test_certificate.html)

cd /etc/apache2/
sudo mkdir certs                                        
cd certs                                                
sudo openssl genrsa -des3 -out server.key 1024          
sudo openssl req -new -key server.key -out server.csr

  Country Name (2 letter code) [GB]:US
  State or Province Name (full name) [Berkshire]:California 
  Locality Name (eg, city) [Newbury]:LA
  Organization Name (eg, company) [My Company Ltd]:Company
  Organizational Unit Name (eg, section) []:
  Common Name (eg, your name or your server's hostname) []:dev.test.local
  Email Address []:username@gmail.com
  Please enter the following 'extra' attributes
  to be sent with your certificate request
  A challenge password []:
  An optional company name []:

sudo cp server.key server.key.org     
sudo openssl rsa -in server.key.org -out server.key
sudo openssl x509 -req -days 730 -in server.csr -signkey server.key -out server.crt  

接下来我为我的 apache 配置文件设置了以下内容:

etc/apache2/httpd.conf:

LoadModule ssl_module libexec/apache2/mod_ssl.so
LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so
Include /private/etc/apache2/extra/httpd-ssl.conf

etc/apache2/extra/httpd-ssl.conf:

Listen 443
SSLPassPhraseDialog  builtin
<VirtualHost _default_:443>
SSLEngine on
Mutex sysvsem default # Added after seeing mutex issues for apache 2.4, http://stackoverflow.com/questions/13969272/apache-sslmutex-issue

etc/apache2/extra/httpd-vhosts.conf:

<VirtualHost *:443>

    ServerName dev.test.local
    DocumentRoot "/Users/username/Sites/test/public"

    <Directory "/Users/username/Sites/test/public">
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Order allow,deny
         allow from all
    </Directory>

    SSLEngine on       
    SSLCertificateFile    /etc/apache2/certs/server.crt
    SSLCertificateKeyFile /etc/apache2/certs/server.key

</VirtualHost>

重新启动并运行 apache config test 后,看起来好像没有问题:

sudo apachectl restart
sudo apachectl configtest
[Tue Jan 06 13:56:01.480270 2015] [so:warn] [pid 31636] AH01574: module php5_module is already loaded, skipping
Syntax OK

非常感谢您的帮助,如果需要,我很乐意提供更多信息。

【问题讨论】:

  • 由于您验证了密钥和证书匹配,因此失败的主要原因在于对包含它们的文件的访问。例如,当您创建 certs 子目录时,读取该子目录的权限是什么?
  • 另外,您是否给您的密钥设置了密码? apache 也需要找到它。
  • 啊,好吧,所以我认为这可能是文件权限的问题,我给了文件完全权限,但没有运气。 drwxrwxrwx 6 根轮 204 证书
  • 是的,我确实添加了密码,我是否错过了其他一些密码设置?或者这是否涵盖了这一点? cp server.key server.key.org openssl rsa -in server.key.org -out server.key
  • 出于测试目的,请生成不带短语的新证书+密钥并尝试。如果它有效,那么我希望某个好心人会为您指出正确的 apache 配置文件设置,以便在您的证书+密钥对中使用密码。

标签: php ssl ssl-certificate osx-yosemite apache2.4


【解决方案1】:

我遇到了同样的问题。 现在我解决了。

你包括

/private/etc/apache2/extra/httpd-ssl.conf 

在 httpd.conf 中。

所以你仍然需要在'httpd-ssl.conf'中设置以下键

SSLCertificateFile "path to your crt"
SSLCertificateKeyFile "path to your key"

希望对你有帮助。

【讨论】:

    【解决方案2】:

    更新到 Apache 2.4.33 后,我遇到了同样的错误。似乎 SSLCertificateFileSSLCertificateKeyFile 现在必须在 &lt;VirtualHost&gt; 块内,而以前它们没有。

    【讨论】:

      【解决方案3】:

      我在更新到 Apache 2.4.33 后遇到了这个问题。

      我必须在我的 httpd-vhosts.conf 文件中 &lt;VirtualHost&gt;&lt;/VirtualHost&gt; 块。我删除了这个:

      <VirtualHost *:443>
          ServerName "<your server name>"
          DocumentRoot "<your path>"
      </VirtualHost>
      

      重启了 apache 就可以了。

      【讨论】:

      • 您能否详细说明您的具体操作?谢谢:)
      • 嘿,我找到了我的 httpd-vhosts.conf 文件并删除了上面显示的代码块。此后似乎奏效了。
      • 感谢詹姆斯的回复!我已经设法解决了这个问题!它确实在删除块` ...... `
      【解决方案4】:

      我今天刚升级到 MacOS High Sierra 版本 10.13.6 后遇到了这个问题。 我的带有 SSL 的虚拟主机在升级之前工作正常。 然后今天,当我尝试启动我的 Apache Web 服务器时,我收到了这个错误:

      [Fri Jul 20 10:51:06.021778 2018] [ssl:emerg] [pid 2236] AH02572: Failed to configure at least one certificate and key for work.localweb.com:80
      [Fri Jul 20 10:51:06.022024 2018] [ssl:emerg] [pid 2236] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned
      [Fri Jul 20 10:51:06.022037 2018] [ssl:emerg] [pid 2236] AH02312: Fatal error initialising mod_ssl, exiting.
      AH00016: Configuration Failed
      

      检查我的 apache 版本,现在是 2.4.33。 显然,在这个版本中,您需要将 SSLCertificateFile 和 SSLCertificateKeyFile 条目放在虚拟主机本身中。 因此,我从 extra/httpd-ssl.conf 中复制了这些条目,并将其放入我配置的每个 SSL 虚拟主机中。

      <VirtualHost *:443>
        ServerAdmin me@mymail.com
        ServerName work.localweb.com
        SSLCertificateFile "/private/etc/apache2/server.crt"
        SSLCertificateKeyFile "/private/etc/apache2/server.key"
        ......
      </VirtualHost>
      

      然后重新启动。

      【讨论】:

      • Jep,这也为我修复了它我还在 下面直接添加了“SSLEngine on”,然后是 SSLCertificateFile、SSLCertificateKeyFile、SSLCertificateChainFile 等。
      【解决方案5】:

      我也遇到了同样的问题。就我而言,我也刚刚包含了额外的/httpd-ssl.conf,正如其他一些人提到的那样。 如上所述,请确保您在此文件中有

      的条目

      SSLCertificateFile "/usr/local/etc/apache24/ssl.crt/mydomaincertificate.crt"

      SSLCertificateKeyFile "/usr/local/etc/apache24/ssl.key/myprivatekey.key"

      即使我的主域的 extra/httpd-vhosts.conf 中有相同的条目。 我还必须确保 httpd.conf 中的“ServerName”条目与证书中的名称匹配。

      虽然这对 OP 没有用,但它可能对像我这样的人在设置 SSL 后搜索此错误有用

      【讨论】:

        【解决方案6】:

        希望对新来的访客有所帮助。

        我在日志文件中有相同的错误行。

        我的错误是包含

        SSLEngine on
        

        VirtualHost 块之外,在.conf 文件中,以及SSLProtocolSSLCipherSuiteSSLHonorCipherOrder 的常用值...

        【讨论】:

          猜你喜欢
          • 2017-10-09
          • 1970-01-01
          • 2020-03-19
          • 1970-01-01
          • 2019-03-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-21
          相关资源
          最近更新 更多