Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple ssl virtual hosts on apache

Tags:

ssl

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!

like image 642
gaspar Avatar asked Sep 24 '14 13:09

gaspar


2 Answers

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.

like image 72
gaspar Avatar answered Sep 16 '22 15:09

gaspar


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
like image 34
Rogelio Triviño Avatar answered Sep 19 '22 15:09

Rogelio Triviño