Wampserver: Apache vhost 配置與 DocumentRoot 關系

  • 安裝

安裝完成 Wampserver 3.0.6,修改 DocumentRoot。

  • 修改 DocumentRoot
    修改服務器根目錄路徑:/wampserver_intall_dir/to/bin/apache/.../conf/httpd.conf

搜索 “DocumentRoot”,將當前行與下一行的目錄路徑,都修改為指定的根目錄路徑。

重啟,http://localhost 發現返回相應沒有改變。

  • 測試
    用一個錯誤的路徑“D:\htdocs\”測試,發現 Wampserver 重啟后,出現服務狀態不正常。這說明配置文件肯定是修改對了。

右鍵點擊,使用 Wampserver 工具 "Check httpd.conf syntax",提示 DocumentRoot must be a directory。Windows 中,使用右斜線()表示路徑,結尾處不能帶有 \ 。如果使用左斜線(/),結尾處可帶上左斜線(/),也可以不需要。

確認修改的配置文件是正確的,為什么不生效呢?檢查發現,apache 指定了一個 virtualhost:

<VirtualHost *:80>
ServerName localhost
DocumentRoot D:/wamp/wamp64/www
<Directory "D:/wamp/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>

注釋 httpd-vhosts.conf 文件中 vhost 配置,重啟 Wampserver,刷新頁面就正常了。

  • Conclude
    httpd-vhosts.conf 文件中,為某個 ServerName 指定的 DocumentRoot 是獲得最高優先級的,而不會使用 httpd.conf 中所指定的。

  • 去掉 VirtualHost 配置中的 DocumentRoot 與 Directory

DocumentRoot D:/wamp/wamp64/www
<Directory "D:/wamp/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>

請求 "http://localhost",發現 httpd.conf 中使用 DocumentRoot 的生效了。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容