了解Apache虚拟主机文件

从“ Apache食谱 ”,我的注释是否正确?

假设: 10.0.0.1 DNSconfiguration正确。

 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> 

如果我只input“ 10.0.0.1 ”,那么第一个虚拟主机将被击中,这是TheSmiths.name

从Apache文档 :

如果在包含最具体匹配的IP地址和端口组合的虚拟主机组中找不到匹配的ServerName或ServerAlias,则将使用与之匹配的第一个列出的虚拟主机。

这意味着,如果您将浏览器指向http://10.0.0.1/ (并且不另外提供Host:标头),该请求将由虚拟主机为TheSmiths.name ,因为这是第一个列出的VirtualHost在configuration中。

除虚拟主机之外,Apache通常会访问默认站点。 但是,如果您没有启用默认站点,那么是的,它将为它find的第一个VirtualHost服务。

由于NameVirtualHosts是名称驱动的,这意味着Apache将匹配ServerName请求的主机名来击中正确的站点。