Apache:SSLCertificateKeyFile:文件不存在或为空

blu*_*ast 49 ubuntu ssl mod-ssl ssl-certificate apache-2.2

我正在为Apache 2. 我的系统是Ubuntu Server 10.04 LTS。我的 vhost 配置中有以下与 SSL 相关的设置:

SSLEngine On
SSLCertificateKeyFile /etc/ssl/private/server.insecure.key
SSLCertificateFile    /etc/ssl/certs/portal.selfsigned.crt
Run Code Online (Sandbox Code Playgroud)

(旁注:我使用.insecure密钥文件是因为该文件不受密码保护,我想清楚地看到它是一个不安全的密钥文件)

因此,当我重新启动 apache 时,我收到以下消息:

Syntax error on line 39 of /etc/apache2/sites-enabled/500-portal-https:
SSLCertificateKeyFile: file '/etc/ssl/private/server.insecure.key' does not exist or is empty
Error in syntax. Not restarting.
Run Code Online (Sandbox Code Playgroud)

但是文件在那里,并且不是空的(实际上它包含一个私钥):

sudo ls -l /etc/ssl/private/server.insecure.key
-rw-r----- 1 root www-data 887 2012-08-07 15:14 /etc/ssl/private/server.insecure.key
sudo ls -ld /etc/ssl/private/
drwx--x--- 2 root www-data 4096 2012-08-07 13:02 /etc/ssl/private/
Run Code Online (Sandbox Code Playgroud)

我尝试使用两个组 www-data 和 ssl-cert 更改所有权。我不确定 Ubuntu 中哪个是正确的:默认情况下 Ubuntu 使用 ssl-cert,但另一方面 apache 进程使用用户 www-data 运行:它由用户 root 启动,但在某些情况下更改为 www-data点,我不确定什么时候读取证书。

但无论如何,更换群主并没有改善情况。我的问题是:

  1. 我还能尝试什么来让它工作?
  2. 如何验证我的密钥文件是有效的密钥文件?
  3. 如何验证密钥文件和证书 ( /etc/ssl/certs/portal.selfsigned.crt) 是否协同工作?

我认为 Apache 给出了误导性的错误消息,我想指出错误。

blu*_*ast 59

我发现了错误。这是因为我正在使用脚本来设置证书,而我正在执行的步骤之一是apache2ctl configtest. 错误来自这个命令,而不是来自 apache restart,这是误导我的原因。由于我以普通用户身份运行 apache2ctl 命令,因此它无法访问密钥文件,因此无法访问错误消息。

Facit:确保所有 apache 命令都使用 sudo 运行,即使是仅用于语法验证的命令 ( apache2ctl),因为它们也需要访问密钥。


Ant*_*ioK 14

我也收到消息

SSLCertificateKeyFile: file '/path/to/file' does not exist or is empty
Run Code Online (Sandbox Code Playgroud)

虽然/path/to/file存在并具有正确的权限,只是因为 SELinux 已打开并且 apache 用户无法访问此文件。

它看起来像这样:

$ sudo ls -laZ /etc/pki/tls/certs/
drwxr-xr-x. root root system_u:object_r:cert_t:s0      .
drwxr-xr-x. root root system_u:object_r:cert_t:s0      ..
-rw-------. root root unconfined_u:object_r:cert_t:s0  this-one-works.crt
-rw-------. root root unconfined_u:object_r:admin_home_t:s0 this-one-is-unaccessable.crt
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我运行sudo restorecon -Rv /etc/pki/tls/certs/- 它将修复问题文件的 SELinux 属性。

  • `sudo:restorecon:找不到命令` (2认同)

小智 6

我已经这样做了,它在 CentOS 5.7 上帮助了我

server:~ # chcon -t cert_t /etc/pki/tls/private/my.key 
server:~ # ls -laZ /etc/pki/tls/private/
Run Code Online (Sandbox Code Playgroud)