一台 Apache2 服务器上多个域的 SSL 证书问题

标签 ssl apache2

我有一台运行 LAMP 堆栈的服务器:

me@server:~$ sudo apachectl -v
Server version: Apache/2.4.10 (Debian)

me@server:~$ cat /etc/*-release
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
...

在这台服务器上,我有很多两个域 - 一个有 SSL,一个没有 SSL - 目前一切都很好。

我正在尝试将 SSL 添加到第二个站点,但对第二个站点的请求失败并出现以下问题:

[FIREFOX]
domain2.com uses an invalid security certificate. 
The certificate is only valid for the following names: domain1.com
Error code: SSL_ERROR_BAD_CERT_DOMAIN

[CHROME]
NET::ERR_CERT_COMMON_NAME_INVALID

注意 1:我检查过我的 Apache 版本允许在同一台服务器上使用多个 SSL 站点。

这让我相信调用 domain2.com 时读取的 SSL 文件实际上是与 domain1.com 相关的文件。

奇怪的是,如果我使用 sudo apache dissite domain1 禁用 domain1.com,SSL 在 https://domain2.com 上工作得很好>。这表明 SSL 已正确安装,但服务器上的站点并未全部配置正确。

.conf 文件如下:

me@server:~& cat /etc/apache2/sites-enabled/domain1
[...Port 80 config redacted...]
<VirtualHost *:443>
  SSLEngine on
  SSLProtocol All -SSLv2 -SSLv3
  SSLCertificateFile /etc/apache2/ssl/domain1/server.crt
  SSLCertificateKeyFile /etc/apache2/ssl/domain1/key.txt
  SSLCertificateChainFile /etc/apache2/ssl/domain1/intermediate.crt

  ServerName domain1.com
  ServerAlias www.domain1.com

  <Directory /var/www/domain1>
    [REDACTED]
  </Directory>

  [Logging information redacted]
</VirtualHost>

    me@server:~& cat /etc/apache2/sites-enabled/domain2
[...Port 80 config redacted...]
<VirtualHost *:443>
  SSLEngine on
  SSLProtocol All -SSLv2 -SSLv3
  SSLCertificateFile /etc/apache2/ssl/domain2/server.crt
  SSLCertificateKeyFile /etc/apache2/ssl/domain2/key.txt
  SSLCertificateChainFile /etc/apache2/ssl/domain2/intermediate.crt

  ServerName domain2.com
  ServerAlias www.domain2.com

  <Directory /var/www/domain2>
    [REDACTED]
  </Directory>

  [Logging information redacted]
</VirtualHost>

很明显,两个站点都应用了相同的配置项,但与该站点服务器上的特定 SSL 文件相关。请注意,每个站点的 SSL 包均由同一供应商提供。

此外,证书应该是正确的:

me@server:/etc/apache2/ssl/domain1$ openssl x509 -in server.crt -noout -subject
subject= /CN=www.domain1.com

me@server:/etc/apache2/ssl/domain2$ openssl x509 -in server.crt -noout -subject
subject= /CN=www.domain2.com

从所有这些中,请告诉我为什么启用 domain1.com 时对 domain2.com 的请求失败?

最佳答案

所以是的.. 执行上述操作都很好并且应该有效。

如果不起作用,请务必检查 ServerName 字段的拼写,并且不要在深夜工作!

关于一台 Apache2 服务器上多个域的 SSL 证书问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42798693/

相关文章:

ssl - 在 Tomcat 5 中启用强密码

linux - 无法从ubuntu发送邮件

python - 从 apache 中的 python 脚本关闭计算机

apache - "ExpiresDefault access"与 "ExpiresDefault access plus zero seconds"

php - cURL 请求在服务器上工作正常但不会在我的本地主机上工作 :8080

c# - WCF – SSL – 客户端身份验证 – 无法在 Windows 7 上实现,而我可以在 Windows XP 上实现

amazon-web-services - 从 AWS Amplify 部署的 HTTPS (SSL) 客户端向 HTTP 端点发出 API 请求

c# - .NET HttpListener - 设置浏览器代理时监听 "https://*.8080"时没有流量?

ruby-on-rails - 在Rails Controller 中需要 ruby gem

Apache/Tomcat 的 SSL 证书