- 確保 httpd.conf 配置文件,已將引入虛擬機(jī)配置打開(kāi)
Include conf/extra/httpd-vhosts.conf
- 打開(kāi) 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 .
服務(wù)器如何選擇合適的"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 解決方案的第一步,就是通過(guò) IP-based來(lái)解決的。
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 在將匹配范圍縮小,直到匹配到最準(zhǔn)確的 IP。在所有的 VirtualHost 指令中,使用通配符(*)作為 IP 地址,將會(huì)使 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 當(dāng)一個(gè)請(qǐng)求到達(dá)時(shí),服務(wù)器會(huì)以發(fā)起請(qǐng)求的 IP 地址和端口為基礎(chǔ),找到匹配度最高的參數(shù)。
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 如果存在多個(gè)虛擬機(jī),都包含了匹配的 IP 地址與端口組合,Apache 會(huì)進(jìn)一步比較 ServerName 指令、ServerAlias 指令與請(qǐng)求中發(fā)送的 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 如果你在任一個(gè) name-based virtual host 中,都沒(méi)使用 ServerName 指令,服務(wù)器默認(rèn)會(huì)使用來(lái)自系統(tǒng) hostname 的全域名。這種隱藏的 server name 設(shè)置會(huì)導(dǎo)致反直覺(jué)的 host 匹配,不鼓勵(lì)這種做法。
詳情參考,官方手冊(cè)地址
- Windows 測(cè)試虛擬機(jī)配置命令,進(jìn)入到 /apache_install_path/to/bin/
httpd.exe -S
-
Check httpd.conf syntax | 檢查配置文件的語(yǔ)法,截圖如下:
check_httpdconf_syntax.png
提示:
<Directory "F:\projects\trunk"> path is invalid.
** httpd-vhosts.conf ** 配置內(nèi)容:
<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>
