Apache2: While redirecting 2nd website http to https, it always rewdirects to 1st domain

All my Vhost config files have a <virtualhost *:443> and a <virtualhost *:80> in each. There is no default host declared. Apache2 is selecting my vhost #1 as a default. Vhost #1 is now working as expected with any request addressed to http:// gets rerouted to https://www.vhost-1. I am now trying to set up vhost-2 to do the same thing but no matter what I do, a request sent to http://vhost-2.com will always end up at http://www.vhost-1. There is nothing in any of the logs that indicate any kind of error but logs do show that https://www.vhost-2.com is being accessed. I am assuming that it then gets rerouted again to https://www.vhost-1. I removed all but sleepyvalley and ancienttom config files from sites-enabled. I see nothing in any other file triggering a second redirect, either directly to vhost-1 or to it as the default website. I have been working all day searching through all of my config files for any possible entries that may be causing this without any success.

Vhost-1

<VirtualHost *:443>

    ServerAdmin webmaster@sleepyvalley.net

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/sleepyvalley.crt
    SSLCertificateKeyFile //etc/ssl/private/sleepyvalley.key

    ServerName www.ancienttom.com
    ServerAlias ancienttom.com ancienttom.us www.ancienttom.us

    DocumentRoot /var/www/html/ancienttom

    <Directory /var/www/html/ancienttom>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        DirectoryIndex index.html index.htm index.php index.php5
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName ancienttom.com
    Serveralias www.ancienttom.com ancienttom.us www.ancienttom.us
    Redirect permanent / https://www.ancienttom.com/
</VirtualHost>

vhost-2 <VirtualHost *:443> ServerAdmin webmaster@sleepyvalley.net

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/sleepyvalley.crt
    SSLCertificateKeyFile //etc/ssl/private/sleepyvalley.key

    ServerName www.ancienttom.com
    ServerAlias ancienttom.com ancienttom.us www.ancienttom.us

    DocumentRoot /var/www/html/ancienttom

    <Directory /var/www/html/ancienttom>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        DirectoryIndex index.html index.htm index.php index.php5
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName ancienttom.com
    Serveralias www.ancienttom.com ancienttom.us www.ancienttom.us

    Redirect permanent / https://www.ancienttom.com/
</VirtualHost>

Straight answer:

Your vhost-1 and vhost-2 are identical — both have the same ServerName and ServerAlias:

ServerName www.ancienttom.com  
ServerAlias ancienttom.com ancienttom.us www.ancienttom.us

This means Apache has no way to distinguish them, so it defaults to the first one it sees.


What you must do:

You say you’re trying to set up vhost-2 for vhost-2.com, but your config still references ancienttom.com in both.

Fix this: update vhost-2’s config to use the correct domain:

# For vhost-2 (example: sleepyvalley.net)

<VirtualHost *:443>
    ServerAdmin webmaster@sleepyvalley.net

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/sleepyvalley.crt
    SSLCertificateKeyFile //etc/ssl/private/sleepyvalley.key

    ServerName www.sleepyvalley.net
    ServerAlias sleepyvalley.net

    DocumentRoot /var/www/html/sleepyvalley

    <Directory /var/www/html/sleepyvalley>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        DirectoryIndex index.html index.htm index.php index.php5
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName sleepyvalley.net
    ServerAlias www.sleepyvalley.net

    Redirect permanent / https://www.sleepyvalley.net/
</VirtualHost>

Summary:

Your current vhost-2 config still points to ancienttom.com, so it’s not matching vhost-2.com (or sleepyvalley.net) at all. Apache sees two configs for the same domain and uses the first one.

Update the ServerName, ServerAlias, and DocumentRoot in the second config to match your actual second domain, and it will work.