Solution 1:

Make sure that the order of precedence in configuration directives matches how Apache should handle the request - i.e. you won't have much luck if your directives load like this:

  • example.com
  • default/catch-all
  • universal.lv

Doesn't matter whether they are declared in a single file or multiple files - so long as "universal.lv" is last, it will not be reached because the default/catch-all vhost will precede it.

I usually name my default/catch-all config "z-default.conf" (or, if you have a domain that starts with a "z", "zz" ... etc) for this reason, to ensure that it is processed only if no other vhost matches.

Try renaming accordingly.


Updated: So as not to confuse w/the _default_ VirtualHost directive

Using wildcard DNS to direct all requests to example.com to the server's IP (catches mis-keyed subdomains), Apache parses the following configuration files:

  • 000-default.conf - VirtualHost _default_:80 / ServerName <hostname> - catch requests against the server's IP (can redirect to primary domain or simply block with the default Directory specified in conf.d/security)
  • example.conf - VirtualHost *:80 / ServerName www.example.com
  • example2.conf - VirtualHost *:80 / ServerName www.example2.com
  • zzz-example.conf - VirtualHost *:80 / ServerName example.com / ServerAlias *.example.com - redirects to canonical www domain
  • zzz-example2.conf - VirtualHost *:80 / ServerName example2.com / ServerAlias *.example2.com - redirects to canonical www domain

As documented, Apache selects the first matching VirtualHost (i.e. _default_:80) but this behavior is not desirable if you are using a wildcard in a ServerAlias directive.

Solution 2:

I recommend you to read the Apache documentation on Virtual Hosts first.

An excellent example has been given on http://httpd.apache.org/docs/2.2/vhosts/name-based.html:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

Note the NameVirtualHost part. Your error log (/var/log/apache2/error.log) should have warned you that you've made a possible mistake.

Note: after a change to the configuration file, Apache needs to be restarted.