配置虛擬主機後,訪問 https://localhost/ 回傳 403 Forbidden,但目錄 d:/localhost/ 存在且有權限。調換 80/81 端口順序無效,修改 httpd.conf 權限段落也無效。
Apache 內部快取或 vhost 載入順序導致權限繼承異常。首個 VirtualHost *:80 若缺少顯式 <Directory> 授權,可能繼承預設拒絕規則。
在首個 VirtualHost *:80 區塊內**顯式加入目錄授權**:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "d:/localhost"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
<Directory "d:/localhost">
Options Indexes
Require all granted
</Directory>
</VirtualHost>
<Directory> 區塊。https://localhost/ 應顯示目錄列表(或索引頁)。移除 httpd.conf 全域 <Directory /> 中的 Options Indexes,僅保留 Require all granted,虛擬主機目錄列表功能依然正常。推測 WAMP/Apache 存在殘留快取機制,重啟甚至重裝難以完全清除。
VirtualHost 內顯式宣告 <Directory> Require all granted。<Directory /> 繼承。