HOW-TO: Apache Virtual Host (Multi-Site) and mod_ssl (SSL) can be compatible

Some time ago I found documentation lacking for how to successfully configure name-based Apache Virtual Host (Multi-Site) and allow one of the domain names to have mod_ssl (SSL) enabled while having only a SINGLE static IP address. The answer turned out to be... "You must set up your Apache configuration files correctly!" Here is what I discovered.

First, it is assumed that the server has some hosting provider given real hostname. So I had that be the master Apache website having a couple of extra / necessary entries in that configuration file. I will name the server "s1234567890.serverhosting.com" for this example, and here is a snippet of that domain name's Apache configuration:

NameVirtualHost xxx.xxx.xxx.xxx:80
NameVirtualHost xxx.xxx.xxx.xxx:443

<VirtualHost xxx.xxx.xxx.xxx:80>
   ServerName s1234567890.serverhosting.com
</VirtualHost>

As you configure the filenames of the configuration files, make sure that this "master" file will always be the first file loaded, as Apache Virtual Host (Multi-Site) REQUIRES that the first configuration file loaded include the "NameVirtualHost" entries! I add a numerical prefix to my filenames / symlink names, so the master file becomes 000-*, and the next file becomes 001-*, 002-*, and so on... That makes it very clear what order Apache will load the configuration files as it starts up.

Next up, the domain with mod_ssl (SSL) support enabled for it. Its configuration file is along the lines of this one:

<VirtualHost xxx.xxx.xxx.xxx:80>
   ServerName domain1.com
   ServerAlias www.domain1.com
</VirtualHost>

<VirtualHost xxx.xxx.xxx.xxx:443>
   ServerName domain1.com
   ServerAlias www.domain1.com
</VirtualHost>

Next up, additional domains which CAN NOT have mod_ssl (SSL)

<VirtualHost xxx.xxx.xxx.xxx:80>
   ServerName domain2.com
   ServerAlias www.domain2.com
</VirtualHost>

It is CRITICAL to get this configuration working that the tags have the IP address of the server specified and NOT the Virtual Host hostname. The Virtual Host hostname needs to appear as the ServerName value within the site configuration file.

As well, defining the port number (80 / 443) is also imperative throughout the configuration files.

After finally finding these critical details out, Apache began to behave as desired. :-)