简体   繁体   中英

multiple ssl virtual hosts on apache

I want to configure two virtual hosts with their own ssl certificates on apache (apache 2.2.22 and openssl 1.0.1, debian 7.6). I've found many articles about SNI, but still can't configure it properly. Here's my config:

ports.conf

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

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

test1-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>

Domain https://test1.com works properly (with its own certificate). Domain https://test2.test.pl displays content of domain test1.com and uses test1 ssl certificate instead of test2.crt (as it is defined in config file test2-ssl). Any ideas,sugestions very appreciated.

Kind regards, and thanks in advance!

After little more searching it turns out that it's possible ( https://www.digicert.com/ssl-support/apache-multiple-ssl-certificates-using-sni.htm ). My only problem was two separate configuration files for domains... when I configure virtualhost for domains in one config file it worked.

In my use case, I had 2 certificates, one wildcard and one not. I put on a single file both configs:

<VirtualHost *.wildcard.com:443>
....



<VirtualHost normal.com:443>
...

but didn't work. The solution was this:

<VirtualHost *:443>
....



<VirtualHost *:443>
...

for both domains, provided that on every virtualhost definition you add the desired ServerName and ServerAlias:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM