title: How to configure multiple subdomain with SSL in Apache?
body: <p>Configuration:</p>
  
  <ul>
  <li>Debian</li>
  <li>Apache2</li>
  <li>Wildcard SSL for: *.example.com</li>
  <li>subdomain: a.example.com, b.example.com.</li>
  <li>1 dedicated server</li>
  <li>Websites are in NodeJS (ProxyPass...)</li>
  </ul>
  
  <p>For now, i'm able to get a.example.com to work.
  But how i can make a.example.com AND b.example.com working on the same server ?</p>
  
  <pre><code>/etc/apache2/site-enable/a.example.com.conf
  &lt;VirtualHost  *:80&gt;
    ServerName a.example.com
    Redirect permanent / https://a.example.com
  &lt;/VirtualHost&gt;
  &lt;VirtualHost  *:80&gt;
    ServerName www.a.example.com
    Redirect permanent / https://a.example.com
  &lt;/VirtualHost&gt;
  Listen 443
  
  &lt;VirtualHost *:443&gt;
   ServerName a.example.com
   ServerAlias www.a.example.com
  
   ProxyRequests off
   LimitRequestLine  150000
   LimitRequestFieldSize 150000
   &lt;Proxy *&gt;
    Order deny,allow
    Allow from all
   &lt;/Proxy&gt;
  
   &lt;Location /&gt;
    ProxyPass http://localhost:4949/
    ProxyPassReverse http://localhost:4949/
   &lt;/Location&gt;
  
   SSLEngine on
   SSLProtocol all -SSLv2 -SSLv3
   SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL
  
   SSLCertificateFile   /etc/ssl/2__.example.fr.crt
   SSLCertificateKeyFile  /root/XXXXXX.key
   SSLCertificateChainFile    /etc/ssl/1_root_bundle.crt 
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>UPDATE ---
  If i try this:</p>
  
  <pre><code>/etc/apache2/site-enable/b.example.com.conf
  &lt;VirtualHost  *:80&gt;
  ServerName b.example.com
  Redirect permanent / https://b.example.com
  &lt;/VirtualHost&gt;
  &lt;VirtualHost  *:80&gt;
  ServerName www.b.example.com
  Redirect permanent / https://b.example.com
  /VirtualHost&gt;
  
  Listen 443
  
  &lt;VirtualHost *:443&gt;
   ServerName b.example.com
   ServerAlias www.b.example.com
  
   ProxyRequests off
   LimitRequestLine  150000
   LimitRequestFieldSize 150000
   &lt;Proxy *&gt;
    Order deny,allow
    Allow from all
   &lt;/Proxy&gt;
  
   &lt;Location /&gt;
    ProxyPass http://localhost:6949/
    ProxyPassReverse http://localhost:6949/
   &lt;/Location&gt;
  
   SSLEngine on
   SSLProtocol all -SSLv2 -SSLv3
   SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL
  
   SSLCertificateFile   /etc/ssl/2__.example.fr.crt
   SSLCertificateKeyFile  /root/XXXXXX.key
   SSLCertificateChainFile    /etc/ssl/1_root_bundle.crt 
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>I'm getting this</p>
  
  <pre><code>[....] Restarting web server: apache2[Thu Jul 21 14:58:01 2016] [warn] module passenger_module is already loaded, skipping
  [Thu Jul 21 14:58:01 2016] [warn] _default_ VirtualHost overlap on port 443, the first has precedence
  [Thu Jul 21 14:58:01 2016] [warn] NameVirtualHost *:80 has no VirtualHosts
   ... waiting [Thu Jul 21 14:58:02 2016] [warn] module passenger_module is already loaded, skipping
  [Thu Jul 21 14:58:02 2016] [warn] _default_ VirtualHost overlap on port 443, the first has precedence
  [Thu Jul 21 14:58:02 2016] [warn] NameVirtualHost *:80 has no VirtualHosts
  (98)Address already in use: make_sock: could not bind to address [::]:443
  </code></pre>
  
  <p>--- UPDATE </p>
  
  <p>I removed Listen 443 on b.exemple.com.conf</p>
  
  <p>But now, i have this:</p>
  
  <pre><code>a.example.com ---&gt; b.example.com
  b.example.com ---&gt; b.example.com
  </code></pre>
  
  <p>The problem is that when i try to access to a, i'm redirected to b</p>
  
  <p>What i'm doing wrong ?</p>
  
  <pre><code>/etc/apache2/site-enable/b.example.com.conf
  &lt;VirtualHost  *:80&gt;
  ServerName b.example.com
  Redirect permanent / https://b.example.com
  &lt;/VirtualHost&gt;
  &lt;VirtualHost  *:80&gt;
  ServerName www.b.example.com
  Redirect permanent / https://b.example.com
  /VirtualHost&gt;
  
  &lt;VirtualHost *:443&gt;
   ServerName b.example.com
   ServerAlias www.b.example.com
  
   ProxyRequests off
   LimitRequestLine  150000
   LimitRequestFieldSize 150000
   &lt;Proxy *&gt;
    Order deny,allow
    Allow from all
   &lt;/Proxy&gt;
  
   &lt;Location /&gt;
    ProxyPass http://localhost:6949/
    ProxyPassReverse http://localhost:6949/
   &lt;/Location&gt;
  
   SSLEngine on
   SSLProtocol all -SSLv2 -SSLv3
   SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL
  
   SSLCertificateFile   /etc/ssl/2__.example.fr.crt
   SSLCertificateKeyFile  /root/XXXXXX.key
   SSLCertificateChainFile    /etc/ssl/1_root_bundle.crt 
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p><strong>-- UPDATE FOUND A SOLUTION : )</strong></p>
  
  <p>I finally found a solution for my problem, thank you for your help !</p>
  
  <pre><code>&lt;IfModule mod_ssl.c&gt;
      Listen 443
      NameVirtualHost *:443    
  &lt;/IfModule&gt;
  &lt;VirtualHost *:443&gt;
    ServerName www.example.fr
    DocumentRoot "/var/www/html/404"
  
    SSLEngine on
    SSLProtocol all -SSLv2 -SSLv3
    SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL
  
    SSLCertificateFile   /etc/ssl/2__.example.fr.crt
    SSLCertificateKeyFile  /root/XXXXX.key
    SSLCertificateChainFile    /etc/ssl/1_root_bundle.crt 
  &lt;/VirtualHost&gt;
  &lt;VirtualHost  *:80&gt;
      ServerName www.example.fr
      Redirect permanent / https://a.example.fr
  &lt;/VirtualHost&gt;
  
  
  &lt;VirtualHost  *:80&gt;
      ServerName a.example.fr
      Redirect permanent / https://a.example.fr
  &lt;/VirtualHost&gt;
  &lt;VirtualHost *:443&gt;
    ServerAdmin admin@admin.fr
    ServerName a.example.fr
  
    ProxyRequests off
    LimitRequestLine  150000
    LimitRequestFieldSize 150000
    &lt;Proxy *&gt;
      Order deny,allow
      Allow from all
    &lt;/Proxy&gt;
  
    &lt;Location /&gt;
      ProxyPass http://localhost:4949/
      ProxyPassReverse http://localhost:4949/
    &lt;/Location&gt;
  
    SSLEngine on
    SSLProtocol all -SSLv2 -SSLv3
    SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL
  
    SSLCertificateFile   /etc/ssl/2__.example.fr.crt
    SSLCertificateKeyFile  /root/serveurA.key
    SSLCertificateChainFile    /etc/ssl/1_root_bundle.crt 
  
  &lt;/VirtualHost&gt;
  
  
  
  
  
  &lt;VirtualHost  *:80&gt;
      ServerName b.example.fr
      Redirect permanent / https://b.example.fr
  &lt;/VirtualHost&gt;
  &lt;VirtualHost *:443&gt;
    ServerAdmin admin@admin.fr
    ServerName b.example.fr
  
    ProxyRequests off
    LimitRequestLine  150000
    LimitRequestFieldSize 150000
    &lt;Proxy *&gt;
      Order deny,allow
      Allow from all
    &lt;/Proxy&gt;
  
    &lt;Location /&gt;
      ProxyPass http://localhost:6949/
      ProxyPassReverse http://localhost:6949/
    &lt;/Location&gt;
  
    SSLEngine on
    SSLProtocol all -SSLv2 -SSLv3
    SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL
  
    SSLCertificateFile   /etc/ssl/2__.example.fr.crt
    SSLCertificateKeyFile  /root/serveurA.key
    SSLCertificateChainFile    /etc/ssl/1_root_bundle.crt 
  
  &lt;/VirtualHost&gt;
  </code></pre>