ssl - 在 apache 上托管多个 SSL 证书

标签 ssl apache2

我希望有人能帮我解决这个问题。我有 2 个 IP 可用于执行此操作,并且需要在同一 Apache 服务器上托管 2 个不同的安全 (SSL) 域。我读过 Apache 2.2.something 可以使用单个 IP,使用某种加载项,但我希望尽可能简单,并且愿意使用两个 IP 来完成此任务。我已经拥有域的 2 个签名证书。

我在此处发布的此设置有效,但我遇到的问题是,当我转到 domain2.net 时,我收到浏览器警告,告诉我该证书与域不匹配,但与 domain1.com 匹配

我使用的是 CentOS 5 和 Apache 2.2.3。 CentOS 有一个 ssl.conf 文件,我认为这些行给我带来了麻烦:

SSLCertificateFile /etc/pki/tls/certs/domain1.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/domain1.com.key

我的印象是我可以在虚拟主机容器中覆盖这些值并引用我需要的键,但它并没有那样出现。当我在 ssl.conf 文件中注释掉这两行时,Apache 不会重新启动。 ssl_log 提示:SSLCertificateKeyFile

这些是我的虚拟容器:

<VirtualHost 2.2.2.2:443>
   SSLEngine on
   SSLCertificateFile /etc/pki/tls/certs/domain2.net.crt
   SSLCertificateKeyFile /etc/pki/tls/private/domain2.net.key

  DocumentRoot "/var/www/domain2"
   ServerName domain2.net
   ServerAlias domain2.net
   DirectoryIndex "index.php"

   <Directory /var/www/html/domain2>
     Options -Indexes FollowSymLinks
     AllowOverride All
     Order allow,deny
     Allow from all
   </Directory>
</VirtualHost>


<VirtualHost 1.1.1.1:444>
   SSLEngine on
   SSLCertificateFile /etc/pki/tls/certs/domain1.com.crt
   SSLCertificateKeyFile /etc/pki/tls/private/domain1.com.key

  DocumentRoot "/var/www/html"
   ServerName domain1.com
   ServerAlias domain1.com
   DirectoryIndex "index.php"

   <Directory /var/www/html>
     Options -Indexes FollowSymLinks
     AllowOverride All
     Order allow,deny
     Allow from all
   </Directory>
</VirtualHost>

如何使用 SSL 让这两个域正常工作?我也尝试过为不同的 IP 使用相同的端口,但同样,Apache 不会重新启动。

我真的迷失在这件事上,所以如果有人能伸出援手,我将不胜感激。

最佳答案

好问题!

我能够在同一台服务器上获得两个 SSL 证书。你应该能够做你想做的事。

你的配置中让我觉得奇怪的地方:

  1. 我建议对两个受 SSL 保护的站点使用端口 443。你应该在 apache 的 conf 文件中的某个地方有一个特定的指令来监听端口 443。对我来说它位于/etc/apache2/ports.conf

    Listen 443
    

    .

  2. 您让 ServerName 和 ServerAlias 在每个虚拟主机上都使用同一个域,这似乎很奇怪。尝试使 ServerAlias 不同或将其省略:

    ServerName domain1.com
    ServerAlias www.domain1.com
    

    .

  3. 我假设您在发布的配置文件中替换了 IP 和域。即使它们不是您使用的实际 IP,您也可能需要仔细检查它们是否可以将您带到 SSL 之外的正确位置(因为显然 SSL 不起作用)。

.

查看 apache2 错误日志以获取更多信息。对我来说,日志位于:/var/log/apache2/error.log 。你可以设置它: 错误日志/var/log/apache2/error.log

最后,供您引用的是我的 ssl-default (ssl.conf)。我用您在示例 conf 中使用的域名和 IP 替换了我的域名和 IP。我有多个子域使用 NameVirtualHost,因为我有一个通配符证书:

<IfModule mod_ssl.c>
<Directory />
  Options FollowSymLinks
  AllowOverride All
</Directory>
<Directory /var/www/>
  Options  FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>

NameVirtualHost 1.1.1.1:443
NameVirtualHost 2.2.2.2:443

ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/ssl_access.log combined

<FilesMatch "\.(cgi|shtml|phtml|php)$">
  SSLOptions +StdEnvVars
</FilesMatch>

# 1.1.1.1 = domain1.com

<VirtualHost 1.1.1.1:443>
  ServerName www.domain1.com

  ServerAdmin admin@domain1.com

  SSLEngine on
  SSLCertificateKeyFile /var/www/ssl/domain1.key
  SSLCertificateFile /var/www/ssl/wildcard.domain1.crt

  BrowserMatch ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

  DocumentRoot /var/www/domain1/www.domain1.com/web
  DirectoryIndex index.php index.html
</VirtualHost>

<VirtualHost 1.1.1.1:443>
  ServerName secure.domain1.com

  ServerAdmin admin@domain1.com

  SSLEngine on
  SSLCertificateKeyFile /var/www/ssl/domain1.key
  SSLCertificateFile /var/www/ssl/wildcard.domain1.crt

  BrowserMatch ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

  DocumentRoot /var/www/domain1/secure.domain1.com/
  DirectoryIndex index.php index.html
</VirtualHost>


# 2.2.2.2 = *.domain2.com

<VirtualHost 2.2.2.2:443>
  ServerName admin.domain2.com

  ServerAdmin admin@domain2.com

  SSLEngine on
  SSLCertificateKeyFile /var/www/ssl/domain2.key
  SSLCertificateFile /var/www/ssl/domain2.crt

  BrowserMatch ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

  LogLevel warn
  CustomLog /var/log/apache2/access.log combined
  ErrorLog /var/log/apache2/error.log

  DocumentRoot /var/www/domain2/secure.domain2.com/web
  DirectoryIndex index.php index.html

  php_flag display_errors on
  php_value error_reporting 7
</VirtualHost>

</IfModule>

希望对您有所帮助!!

关于ssl - 在 apache 上托管多个 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5228760/

相关文章:

asp.net - 为什么仅在使用 SSL 和端口 443 时我在端口 80 上收到套接字拒绝错误?

ios - 在服务器上更新 SSL 证书时处理它们

java - 设置 Java SSL ServerSocket 使用的证书

php - 获取 服务器遇到内部错误或配置错误,无法完成您的请求

php - 安装 LAMP - PHP 无法连接 MySQL - 为什么?

web-services - JAX-WS 独立服务器通过证书相互认证

java - 如何设置 Spring Boot 以运行 HTTPS/HTTP 端口

css - apache 服务器上的 django 管理 css

Apache Windows httpd.conf AccessFileName 问题

linux - apache2 网络代理服务器上的多个 NIC