jjbbss
jjbbss

Reputation: 169

apache 2.4 serverAlias with * wildcard overwrittes specificed vhost

I have two vhosts the default one and another one:

<VirtualHost *:80>
    ServerName www.eve-stuff.com
    ServerAlias *.eve-stuff.com
    DocumentRoot /var/www/html/test
    <Directory /var/www/html/test>
        Options +FollowSymLinks
        AllowOverride None
        #Require all denied
    </Directory>
</VirtualHost>

This one should just redirect all subdomains that a not specifically setup to the test directory. This is another vhost i have:

<VirtualHost *:80>
        ServerName dev.eve-stuff.com
        DocumentRoot /var/www/html/dev 
        <Directory /var/www/html/dev>
                Options +FollowSymLinks
                AllowOverride None
        </Directory>
</VirtualHost>

This one should show the dev folder for the dev subdomain.

From what I understood from the apache doc the ServerAlias *.eve-stuff.com in the first host will always catch UNLESS another vhost has specifically been created for the address.

However dev.eve-stuff.com still redirects to the test folder not to the dev folder, as it should.

All dns entries, also for the subdomains, point to the right IP. I am running Apache/2.4.18 (Ubuntu).

Upvotes: 0

Views: 5188

Answers (1)

jjbbss
jjbbss

Reputation: 169

Turns out the order in which it is setup matters. Apache apparently looks for the matching host it can find.
Since the first config was in 000-default.conf and the second one was in the 020-dev.conf the dev-subdomain matched the first vhost and used that.
I changed default to 999-default.conf which means now dev will first be matched with the proper vhost but other undefined subdomains will still be matched with the default vhost.

Upvotes: 2

Related Questions