I want to know the difference between "default:*" and "*:*" in VirtualHost Context.
<VirtualHost _default_:*>
#...
ServerName host.example.com
#...
</VirtualHost>
<VirtualHost *:*>
#...
ServerName host.example.com
#...
</VirtualHost>
I don't know the difference and the porpouse of use.
Thk
Best Answer
Solution is on Apache 2.2 documentation on the Virtualhost directive:
Two ways of handling Virtualhosts exists, Name based virtualhosting and IP based Virtualhosting.
With named based virtualhosts you have a list of virtualhosts, each one managing one or several domain names, and each one associated with a couple
listening IP:port
.*
is a special value which mean all IPs on this host. The default virtualHost is the first declared one on this list for each given listening address.With IP based VirtualHosts the
ServerName
directive of the VirtualHost is not used, the important information is the listening IP (and port), and the default VirtualHost is the first one matching the IP handling the incoming request..So with a named based virtualhosting configuration:
<Virtualhost *:80> with ServerName foo.com
means "on all IPs managed on this host", "on port 80", "if the request host header is foo.com" I'll use this virtualhost<Virtualhost *:*> with Servername foo.com
means "on all IPs managed on this host", "on all ports", "if the request host header is foo.com" I'll use this virtualhost<Virtualhost 10.0.0.2:*> with Servername foo.com
means "for request incoming from my network interface 10.0.0.2", "on all ports", "if the request host header is foo.com" I'll use this virtualhost<Virtualhost _default_:*> with Servername foo.com
: should not be used with name based virtualhostingAnd on an IP based Virtualhosting:
<Virtualhost 10.0.0.2:*>
means "I'll use this virtualhost for request coming on my 10.0.0.2 interface"<Virtualhost _default_:443>
means "I'll use this virtualhost for all other network interface on my host for request coming on port 443"<Virtualhost _default_:*>
means "I'll use this virtualhost for all other network interface on my host, if it is not matched by a previous rule, and if the request host header is not matched by a named based virtualhost"So it's all about defining a catch-all Virtualhost. Documentation adds:
So after all theses things it becomes quite "clear" that mixing IP-based and name-based virtualhosting could become a mess. With Apache 2.2 Name based virtualhosting was used only if
NameVirtualhost <something>
was used.But with the new Apache 2.4 version theses things are really easier to understand, no
NameVirtualhost
declaration. The NameVirtualHost directive no longer has any effect, other than to emit a warning. Any address/port combination appearing in multiple virtual hosts is implicitly treated as a name-based virtual host. No more complex thoughs, even the documentation is now simplier:So with apache 2.4 the answer is, it's the same thing.