在Apache上使用多个SSL虚拟主机

18

我希望在Apache(apache2.2.22和openssl1.0.1,debian7.6)上配置两个具有自己SSL证书的虚拟主机。我找到了许多关于SNI的文章,但仍然无法正确配置。下面是我的配置信息:

ports.conf

    NameVirtualHost *:80
    NameVirtualHost *:443
    Listen 80
    <IfModule mod_ssl.c>
       Listen 443
    </IfModule>

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

测试1-ssl

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName test1.com
        DocumentRoot /var/www/test1
        SSLEngine on
        SSLCertificateFile    /etc/apache2/ssl/test1.crt
        SSLCertificateKeyFile /etc/apache2/ssl/test1.key
</VirtualHost>
</IfModule>

test2-ssl

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName test2.test.pl
        DocumentRoot /var/www/test2
        SSLEngine on
        SSLCertificateFile    /etc/apache2/ssl/test2.crt
        SSLCertificateKeyFile /etc/apache2/ssl/test2.key
</VirtualHost>
</IfModule>

域名https://test1.com正常工作(使用自己的证书)。

域名https://test2.test.pl显示了test1.com的内容,并且使用了test2-ssl配置文件中定义的test2.crt证书而不是test1的ssl证书。

非常感谢您的关注和建议。


无法完成此操作:https://wiki.apache.org/httpd/NameBasedSSLVHosts - arco444
2个回答

25

6
即便我的所有内容都在同一个文件中,但我仍然遇到了同样的问题。后来发现我漏掉了这一行:NameVirtualHost *:443 - Kevin Sheehan
在Apache 2.4中,不再需要使用“NameVirtualHost”。此外,第一个定义的VirtualHost是默认值,如果客户端提供的服务器名称不存在于任何虚拟主机中,则使用该默认值。 - caiofior

1
在我的使用案例中,我有两个证书,一个是通配符,另一个不是。我将这两个配置都放在了一个单独的文件中:
<VirtualHost *.wildcard.com:443>
....



<VirtualHost normal.com:443>
...

但没有起作用。解决方案是这个:
<VirtualHost *:443>
....



<VirtualHost *:443>
...

对于两个域名,只要在每个虚拟主机定义中添加所需的 ServerName 和 ServerAlias:

   ServerName normal.com
   ServerAlias www.normal.com
   ServerAlias m.normal.com
   etc

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接