Apache SNI namevhosts总是路由到第一个VirtualHost条目

无论服务器名称/ ServerAlias字段中的SNI匹配如何,Apache似乎都将所有https请求路由到第一个<VirtualHost *:443>

Apache是​​用SNI构build的
服务器版本:Apache / 2.2.22(Ubuntu)
服务器内置:Mar 8 2013 15:53:13
OpenSSL 1.0.1 2012年3月14日

error.log报告:

 Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366) 

这表明SNI正在按照http://wiki.apache.org/httpd/NameBasedSSLVHostsWithSNI (你怎么知道你的Apache构build是否支持SNI?)

当使用HTTPS请求时, SSL_TLS_SNI似乎被正确设置(通过phpinfo()validation)

组态:

 <IfModule mod_ssl.c> # If you add NameVirtualHost *:443 here, you will also have to change # the VirtualHost statement in /etc/apache2/sites-available/default-ssl # to <VirtualHost *:443> # Server Name Indication for SSL named virtual hosts is currently not # supported by MSIE on Windows XP. NameVirtualHost *:443 Listen 443 </IfModule> #<VirtualHost *:443> # <Location /> # Order allow,deny # Deny from all # </Location> #</VirtualHost> <VirtualHost *:443> SSLEngine on ServerAdmin webmaster@localhost ServerName server.com ServerAlias server.com DocumentRoot /web/default ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined SSLCertificateFile /path/server.com.crt SSLCertificateKeyFile /path/server.com.key </VirtualHost> <VirtualHost *:443> SSLEngine on ServerAdmin webmaster@localhost ServerName alias.com ServerAlias alias.com DocumentRoot /web/default ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined SSLCertificateFile /path/alias.com.crt SSLCertificateKeyFile /path/alias.com.key </VirtualHost> 

https://server.com和https://alias.com都会尝试从server.com提供证书(以及内容,如果您忽略证书警告)

类似的configuration工作正常使用HTTP:80(只有更改SSLEngine和证书/关键path)

如果我取消注释第一个虚拟主机(限制对定义的站点的HTTPS访问),那么我总是会得到一个SSL错误(即使它是一个定义的站点)

谢谢

编辑:
其他标志

 SSLProtocol all SSLCipherSuite HIGH:MEDIUM SSLStrictSNIVHostCheck on SSLVerifyClient none SSLProxyEngine off 

SSLStrictSNIVHostCheck on因此它应该只支持支持SNI的浏览器

apache2ctl -S输出:

 *:443 is a NameVirtualHost default server server.com (/etc/apache2/sites-enabled/000-default:22) port 443 namevhost server.com (/etc/apache2/sites-enabled/000-default:22) port 443 namevhost alias.com (/etc/apache2/sites-enabled/000-default:39) port 443 namevhost other.com (/etc/apache2/sites-enabled/other:22) 

更新

所以出于一些奇怪的原因,这个问题似乎已经解决了。
也许这是一些奇怪的caching问题或某事(虽然我有apache2ctl stop/start/restartsudo service apache2 stop/start/restart/reload apache2ctl stop/start/restart sudo service apache2 stop/start/restart/reload和已经在服务器本地执行testing以及使用几个不同的机器) 。

如果这个问题可以作为任何参考的话,请随时提出这个问题或留下。
感谢所有的帮助家伙!

你的configuration看起来不错, SSLEngine On指令已包含在内; 根据日志消息,看起来问题来自客户端。

并不是所有的客户都支持SNI,但其中大部分都是。 这取决于如何由SSL系统(在Win XP上不工作)或浏览器(该版本必须是最近的)进行SSL协商。 看一下支持SNI的浏览器列表 。 如果您必须确保所有客户端都能访问您的网站,则由于这些旧版本(浏览器或系统)的原因,您无法使用SNI。 您需要每个ServerName的IP,并使用VirtualHost $ IP_alias:443作为ServerName alias.com,VirtualHost $ IP_server:443作为ServerName server.com,而不是VirtualHost *:443作为两者。

第一个虚拟主机出现错误,因为没有SSLEngine on指令中包含SSLEngine on ,Apache将发送一个没有SSL的HTTP响应。 如果你想要这样的function,你将不得不为另一个站点(可能还有另一个证书,除非你重用一个现有的域名)设置你的默认虚拟主机,即使你想要做的只是返回一个不错的错误。

也许检查证书实际上是不同的? 您的configuration显示正确。

此外,请检查是否没有其他VirtualHost部分在端口443上侦听.Apache将select最匹配的一个,这意味着如果连接的地址更具体,则该条目将优先。 不过,我不认为这是你的问题。

此外,作为一个兴趣点,从用户方面看,如果客户在大多数情况下不支持SNI会发生什么情况。