基于域名虚拟主机配置注意事项

基于域名的虚拟主机

解析流程

第一个virtual host 是默认的virtual host, 如果你配置了Name-based virtual host , 主服务配置将不再被使用

  1. 根据域名,找到相应的IP,通过IP 到达指定的 server
  2. 根据http header 中带的 host xx.domain.com 匹配server 上的对应的VirtualHost
  3. 如果没有匹配到制定的 xx.domain.com 的 virtual host 。则将使用第一个虚拟主机作为默认的主机。
As a consequence, the first listed virtual host is the default virtual host. The DocumentRoot from the main server will never be used when an IP address matches theNameVirtualHost directive. If you would like to have a special configuration for requests that do not	match any particular virtual host, simply put that configuration in a<VirtualHost> container and list it first in the configuration file.

翻译

综上所述,第一个列出的虚拟主机在这里充当了默认虚拟主机的角色。 当一个IP地址与NameVirtualHost指令中的配置相符的时候, 主服务器中的DocumentRoot将永远不会被用到。 所以,如果你想做一个处理不对应任何一个特定虚拟主机的请求的特殊配置的话, 你只要简单的把它的配置放到<VirtualHost>配置段中, 并把它放到配置文件的最前面就可以了。

refer:

  1. http://httpd.apache.org/docs/2.0/vhosts/name-based.html
  2. http://man.chinaunix.net/newsoft/ApacheManual/vhosts/name-based.html

多个配置加载顺序

如果指定 conf/extra/vhost/*.conf, 配置文件的加载顺序为a...x

Include /home/apache/conf/httpd-vhosts.conf
Include extra/httpd-vhosts.conf

refer

http://www.cnphp6.com/archives/60724

原文地址:https://www.cnblogs.com/brookin/p/5219879.html