Ssl – Apache multiple IPs and SSL

apache-2.2sslsubdomainvirtualhost

I have an Apache server running two sub domains, one of them is configured with SSL.

To get the other sub domain to work, we of course had to set up a new IP (because the other one was configured with SSL).

However, we cannot reach our new sub domain and we cannot figure out why. The Apache configuration should be OK.

Here's a snippet of our virtual hosts directives:

# ssl domain
<VirtualHost 1.2.3.4.5:80>
    ServerName sub1.example.com
    DocumentRoot /var/www/sub1

    <Directory "/var/www/sub1">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>


# "regular" domain
<VirtualHost 2.3.4.5.6:80>
    DocumentRoot /var/www/sub2
    ServerName sub2.example.com

    <Directory "/var/www/sub2">
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

Requests to sub1.example.com are OK, but nothing happens when we try sub2.example.com.

The "default" config for Apache is set to:

Listen 80
ServerName sub1.example.com

We are running Apache/2.2.15 on CentOS 6.

Best Answer

For starters, make sure you have something to the tune of this in your config:

NameVirtualHost *:80  
NameVirtualHost *:443

As mentioned in the remarks, I guarantee you that while every unique SSL vhost needs it's own IP Address, you CAN have as many non-SSL (ala port 80) vhosts on any one of those IP's.

The problem you are more than likely coming up against is the way Apache's default mod_ssl config file is set up.

On CentOS it should be in /etc/httpd/conf.d/ssl.conf.

You'll see that for some reason, Apache (CentOS?) has a pre-configured SSL vhost using _default_ in that file - versus a sample at the bottom of httpd.conf, or an entry in sites-available on Debian systems...

I'd wager that this is why your initial SSL config never worked in the first place because it was doubling up on the same IP (default) that's configured using the default SSL vhost in that default ssl.conf file.

Typically when I set up a new CentOS Apache box, I comment out the entire VirtualHost entry in that file and place the config I want alongside all of the others in httpd.conf.

Related Topic