0

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?

2 Answers 2

2

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.

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .