Apache SNI,2 个域,2 个证书,解析为同一文档根目录

Apache SNI,2 个域,2 个证书,解析为同一文档根目录

我目前正在遵循以下指南:https://www.digitalocean.com/community/articles/how-to-set-up-multiple-ssl-certificates-on-one-ip-with-apache-on-ubuntu-12-04

到目前为止,安装过程没有出现任何问题。我使用的是我在http://www.startssl.com/?app=21. 每个都映射到其自己的(正确的)域。

问题是这样的:在 https 下访问任何一个域都会解析到同一个文档根目录,也就是说,如果我访问https://backend.domain2.com,我正确地转到了其 VirtualHost 配置中指示的文档根目录。但是,如果我转到https://email.domain1.com,我被发送到 backend.domain2 的根目录,URL 保持不变,并警告 SSL 证书无效。检查“无效”证书后发现,它是与 backend.domain2 连接的证书。

我在这里做错了什么?两个域的 VirtualHost 配置如下:

<IfModule mod_ssl.c>
        <VirtualHost *:443>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        ServerName mail.domain1.se
        ServerAdmin [email protected]
        ServerAlias www.mail.domain1.se

        DocumentRoot /usr/share/apache2/roundcubemail

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM

    SSLCertificateFile      /etc/ssl/certs/domain1.crt
        SSLCertificateKeyFile   /etc/ssl/private/domain1.key
    #SSLCertificateChainFile /etc/ssl/certs/sub.class1.server.ca.pem

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

        #Alias /mail "/usr/share/apache2/roundcubemail/"

        ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/share/apache2/roundcubemail/$1

    </VirtualHost>
</IfModule>



<IfModule mod_ssl.c>
<VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    ServerName backend.domain2.com
    ServerAdmin [email protected]
    #ServerAlias www.domain2.com

    DocumentRoot /var/www/backend.domain2.com/html

    <Directory />
            Options FollowSymLinks
            AllowOverride None
        </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    #Alias /mail "/usr/share/apache2/roundcubemail/"

    #ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/pegasusgbg.se/html/$1

    SSLEngine On
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM

    SSLCertificateFile /etc/ssl/certs/domain2.crt
    SSLCertificateKeyFile /etc/ssl/private/domain2.key
    #SSLCertificateChainFile /etc/ssl/certs/sub.class1.server.ca.pem
    CustomLog /var/log/apache2/ssl_request_log \
        "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>
</IfModule>

我的 ports.conf 配置是:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default

NameVirtualHost *:80
NameVirtualHost *:443

Listen 80

<IfModule ssl_module>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

答案1

这..

ServerName mail.domain1.se
ServerAdmin [email protected]
ServerAlias www.mail.domain1.se

..和这个..

ServerName backend.domain2.com
#ServerAlias www.domain2.com

..两者都与您所说的正在访问的主机名不匹配。https://domain1.com这些主机名需要与浏览器中请求的主机名完全匹配,才能向客户端提供正确的证书。

答案2

只是为了确认一下,你使用的浏览器版本是否支持 SNI?根据 Wikipedia 的说法,

 As of November 2012, the only major user bases whose browsers do not support 
 SNI appear to be users of Android 2.x (default browser)[2], Internet Explorer 
 on Windows XP[3][4] and versions of Java before 1.7 on any operating system.[5]

或者这里有更详细的列表:http://en.wikipedia.org/wiki/Server_Name_Indication#Client_side

相关内容