I rewritten my whole question ...
So I want to use apache's _default_ in order to match any requests that are not clearly defined as hosts / ServerName on my server.
e.g when accessing server IP http://123.123.123.123 or http://test.mysite.tld (in below example).
See comments before the in below code samples.
# This correctly matches test.mysite.tld because is not defined anywhere, but ONLY if I define :80 here AND on second virtualhost
<VirtualHost _default_:80>
DocumentRoot /var/www/html/default
</VirtualHost>
# this correctly matches mysite.tld and www.mysite.tld and NOT test.mysite.tld , but only when :80 is defined in both virtualhosts
<VirtualHost *:80>
ServerName mysite.tld
ServerAlias www.mysite.tld
DocumentRoot /var/www/html/mysite.tld
</VirtualHost>
Problem is, this only works if both the default and defined virtualhosts are eider both defined as :80 or both :* wildcard.
But in this below example, accessing http://test.mysite.com matches the second vhost, I expect it to match the first default one:
# when this has wildcard port and second has :80, an undefined host like test.mysite.tld matches on second VirtualHost, I expected to match here :(
<VirtualHost _default_:*>
DocumentRoot /var/www/html/default
</VirtualHost>
# I expect this to NOT match test.mysite.tld while I have a wildcard in above virtualhost
<VirtualHost *:80>
ServerName mysite.tld
ServerAlias www.mysite.tld
DocumentRoot /var/www/html/mysite.tld
</VirtualHost>
I am not sure but I understand that this _default_ can only match an undefined host for exact same port pattern, but then I don't really see the point of wildcard port in _default_:*.
Virtualhost order doesn't matter here also, when default one has _default_:* and the defined ones are *:80 then an undefined host like http://test.mysite.tld always matches that defined one on *:80, NOT the _default_.
Hostheader, that is what is used to select the responding virtual host inside the http server by means of theServerNameandServerAliasconfigurations.http://123.123.123.123then it sends this ip as a host header, no ? And if I don't have this IP defined as aServerNameinside a<VirtualHost>then I expect it to match that_default_virtual host. I think the problem here is that this_default_only matches ServerNames that were not defined in any<VirtualHost>but only as long as both virtualhosts clearly specify same exact port config, both wildcard or both defined as80or whatever port.Hostheader, but that is up to the requesting client, obviously. Certainly the http server will not use an address to select the virtual host by means of theServerNameorServerAliasdirectives. That makes no sense simply because no host name has been specified in the request. Instead the server will delegate the request to the first virtual host that matches the request. Which one that is depends on which addresses the virtual hosts did bind to and whether the port matches, obviously.<VirtualHost _default_:*>is invalid. You should see an entry in the http server's error log about that when you restart the server process. You cannot somehow bind to all ports and listen on all ports of a system. Many ports are already blocked, and that simply makes no sense. You can omit the port specification in that directive according to the documentation. I am actually not quite sure what that does, I do not see how the server should know a default port (because the protocol is unknown, but it might simply default to port 80 for historical reasons).<VirtualHost _default_:*>is valid (is in their docs), most probably it means "any port apache listens on", not "listen on all these ports". These are the docs: httpd.apache.org/docs/2.4/vhosts/examples.html#default I am confused, I will do some more experiments.