42

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

49

Solution is on Apache 2.2 documentation on the Virtualhost directive:

Syntax: ... (...) Addr can be:

  • The IP address of the virtual host;
  • A fully qualified domain name for the IP address of the virtual host (not recommended);
  • The character *, which is used only in combination with NameVirtualHost * to match all IP addresses; or
  • The string _default_, which is used only with IP virtual hosting to catch unmatched IP addresses.

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 virtualhosting

And 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:

When using IP-based virtual hosting, the special name _default_ can be specified in which case this virtual host will match any IP address that is not explicitly listed in another virtual host. In the absence of any _default_ virtual host the "main" server config, consisting of all those definitions outside any VirtualHost section, is used when no IP-match occurs. (But note that any IP address that matches a NameVirtualHost directive will use neither the "main" server config nor the _default_ virtual host. See the name-based virtual hosting documentation for further details.)

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:

  • The character *, which acts as a wildcard and matches any IP address.
  • The string _default_, which is an alias for *

So with apache 2.4 the answer is, it's the same thing.

| improve this answer | |
0

_default_ vhosts for all ports

Catching every request to any unspecified IP address and port, i.e., an address/port combination that is not used for any other virtual host.

http://httpd.apache.org/docs/2.2/vhosts/examples.html#default

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.