Why the NameVirtualHost detective?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, all,

First of all, Merry Xmas & Happy New Year!

I'm quite confused about the combination of the "NameVirtualHost" detective and the <VirtualHost> block.

All the Manuals (e.g., [1], [2]) emphasize that "the argument to the <VirtualHost> directive must exactly match the argument to the NameVirtualHost directive." If a NameVirtualHost is defined without corresponding <VirtualHost>, the following information will be shown:
        [warn] NameVirtualHost [IP]:[PORT] has no VirtualHosts

My question is on the other side: what will happen when a <VirtualHost> is defined without NameVirtualHost? Some misconfiguration reports (e.g., [3]) can be found that a <VirtualHost> without NameVirtualHost declaration doesn't work. For example, in [3]: 

-------------------------------------
NameVirtualHost pmcferrin.homedns.org:80
<VirtualHost    pmcferrin.homedns.org:80>
        ...
</VirtualHost>

<VirtualHost genealogy.homedns.org:80>
        ...
</VirtualHost>
-------------------------------------

However, I cannot replay this case. When I configure my Apache like that, both the two <VirtualHost> works. I checked the source code of different Apache version including Apache 1.3.0, 1.3.42, and 2.2.21. Besides some slight difference, the code of the virtual hosting is quite similar, as follows (see apache-1.3.0/src/main/http-vhost.c or httpd-2.2.21/server/vhost.c):

Step 1. define a hash table: ipaddr_chain **iphash_table_tail[]; 
Step 2. Map the NameVirtualHosts into this hash table (i.e., iphash_table_tail)
Step 3. Go through the virtual hosts and put them into the hash table

Note that in Step 3, when getting a <VirtualHost>, Apache first tries to find the NameVirtualHost with the same IP address in the hash table. If the NameVirtualHost cannot be found, Apache will CREATE a new bucket containing the virtual host information and add it into the hash table. This indicates that even if the <VirtualHost> is defined without NameVirtualHost, it can still work. Also, it comes the question: "Why we need the NameVirtualHost detective?" and "Why it's necessary to make <VirtualHost> to match NameVirtualHost"?

Sorry. I'm a newbie to Apache and not very familiar with it. Any comments and discussion will be highly appreciated!!!

Thanks a lot!!!


[1] Apache Documents, http://httpd.apache.org/docs/2.0/vhosts/name-based.html.
[2] httpd wiki, http://wiki.apache.org/httpd/CommonMisconfigurations.
[3] http://marc.info/?t=122682020400002&r=1&w=2


Best regards,
Tianyin


--
Tianyin XU,
http://cseweb.ucsd.edu/~tixu/

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux