4

What is the difference between "NameVirtualHost *" and "NameVirtualHost 0.0.0.0"? Both seem to be implementing name-based virtualhosts, both seem to work. How does "0.0.0.0" become a wildcard?

deadprogrammer
  • 1,661
  • 7
  • 24
  • 25

1 Answers1

3

I believe they are the same from brief look at the code:

AP_DECLARE(void) ap_init_vhost_config(apr_pool_t *p)
{
     ...
}
 /* Parses a host of the form <address>[:port]
...

Then:

if (strcmp(host, "*") == 0) {
        rv = apr_sockaddr_info_get(&my_addr, "0.0.0.0", APR_INET, port, 0, p);
...
else {
        rv = apr_sockaddr_info_get(&my_addr, host, APR_UNSPEC, port, 0, p);

So it looks like * just gets parsed to 0.0.0.0 in this instance, and if it actually is 0.0.0.0 it will get passed as such (Although maybe APR_INET vs. APR_UNSPEC matters, but I think that might just be IPv compatibility thing, so maybe there is a difference in that IPv4 when 0.0.0.0 and IPv6 is possible when *, not sure). But I could be interpreting this totally wrong, you can see for yourself in server/vhost.c.

Kyle Brandt
  • 82,107
  • 71
  • 302
  • 444