Apache Virtual Hosts with SSL

Solution 1:

You have to add to apache conf

NameVirtualHost x.x.x.x:443

with your ip, and then the virtual host

<VirtualHost x.x.x.x:443>
  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/cert.pem
  SSLCertificateKeyFile /etc/apache2/ssl/key.pem
  SSLCertificateChainFile /etc/apache2/ssl/ca.crt

  # ...
</VirtualHost>

Solution 2:

What you're asking for is impossible. SSL is a separate layer that encapsulates your HTTP session, and it occurs before the HTTP session has begun. At this point, it's not possible for Apache to determine which hostname you are trying to access the server by.

You can only use IP-based virtual hosts with SSL.

For more information see this section of the Apache SSL/TLS FAQ.

Edit: Sorry, I misread your question. I assumed you wanted SSL for all of your domains. However, if you look at the same FAQ, the solution to your question is there as well. You need to explicitly specify the ports for your HTTP based NameVirtualHosts.