Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

From "Apache Cookbook," are my annotations correct?

Assumptions: DNS is configured properly for 10.0.0.1.

ServerName 127.0.0.1          // where Tomcat is running
NameVirtualHost 10.0.0.1:80    
<VirtualHost 10.0.0.1:80>     // www.TheSmiths.name loads up
                              // the content at C:/.../TheSmiths
    ServerName TheSmiths.name
    DocumentRoot "C:/Apache/Sites/TheSmiths"
</VirtualHost>
<VirtualHost 10.0.0.1:80>
    ServerName JohnSmith.name // www.JohnSmith.name loads up
                              // the content at C:/.../JustJohnSmith
    DocumentRoot "C:/Apache/Sites/JustJohnSmith"
</VirtualHost>

If I type in just "10.0.0.1," then the first virtual host will be hit, which is TheSmiths.name?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

From the Apache documentation:

If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used.

This means that if you point your browser at http://10.0.0.1/ (and do not otherwise provide a Host: header), that requests will be served by the virtual host for TheSmiths.name, since this is the first VirtualHost listed in the configuration.

share|improve this answer

Usually Apache hits the default site, apart from virtual hosts. But, if you don't have your default site enable, then yes, it will serve the first VirtualHost it finds.

Since NameVirtualHosts are Name driven, that means that Apache will match the hostname requested with ServerName to hit the proper site.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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