- 确保 httpd.conf 配置文件,已将引入虚拟机配置打开
Include conf/extra/httpd-vhosts.conf
- 打开 extra/httpd-vhosts.conf,添加上需要添加的 virtualhost
<VirtualHost *:80>
ServerName www.saiku.cc
DocumentRoot D:\workspances
<Directory "D:\workspances">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
- How the server selects the proper name-based virtual host .
服务器如何选择合适的"name-based virtual host"。
#3.1 It is important to recognize that the first step in name-based virtual host resolution is IP-based resolution.
首先要知道 name-base virtual host 解决方案的第一步,就是通过 IP-based来解决的。
Name-based virtual host resolution only chooses the most appropriate name-based virtual host after narrowing down the candidates to the best IP-based match. Using a wildcard (*) for the IP address in all of the VirtualHost directives makes this IP-based mapping irrelevant.
#3.2 name-base virtual host 在将匹配范围缩小,直到匹配到最准确的 IP。在所有的 VirtualHost 指令中,使用通配符(*)作为 IP 地址,将会使 IP-based 匹配失效。
When a request arrives, the server will find the best (most specific) matching [<VirtualHost>](http://httpd.apache.org/docs/2.4/en/mod/core.html#virtualhost) argument based on the IP address and port used by the request.
#3.3 当一个请求到达时,服务器会以发起请求的 IP 地址和端口为基础,找到匹配度最高的参数。
If there is more than one virtual host containing this best-match address and port combination, Apache will further compare the [ServerName](http://httpd.apache.org/docs/2.4/en/mod/core.html#servername)
and [ServerAlias](http://httpd.apache.org/docs/2.4/en/mod/core.html#serveralias)
directives to the server name present in the request.
#3.4 如果存在多个虚拟机,都包含了匹配的 IP 地址与端口组合,Apache 会进一步比较 ServerName 指令、ServerAlias 指令与请求中发送的 server name。
If you omit the [ServerName](http://httpd.apache.org/docs/2.4/en/mod/core.html#servername)
directive from any name-based virtual host, the server will default to a fully qualified domain name (FQDN) derived from the system hostname. This implicitly set server name can lead to counter-intuitive virtual host matching and is discouraged.
#3.5 如果你在任一个 name-based virtual host 中,都没使用 ServerName 指令,服务器默认会使用来自系统 hostname 的全域名。这种隐藏的 server name 设置会导致反直觉的 host 匹配,不鼓励这种做法。
详情参考,官方手册地址
- Windows 测试虚拟机配置命令,进入到 /apache_install_path/to/bin/
httpd.exe -S
-
Check httpd.conf syntax | 检查配置文件的语法,截图如下:
提示:
<Directory "F:\projects\trunk"> path is invalid.
** httpd-vhosts.conf ** 配置内容:
<VirtualHost *:80>
ServerName www.saiku.cc
DocumentRoot F:\projects\trunk
<Directory "F:\projects\trunk">
#<Directory "D:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>