首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 相關知識

解決 WAMP / Apache 2.4 「Forbidden: You don't have permission to access」權限錯誤

     編輯:PHP 相關知識

Apache 2.4 存取控制指令變更導致的 403 錯誤快速修正

從 Apache 2.2 升級到 2.4 後,存取控制語法全面改用 mod_authz_host 的 Require 指令,舊版的 Order allow,deny / Allow from all 寫法將不再生效,導致虛擬主機或目錄出現 403 Forbidden。

錯誤原因

預設配置 httpd.conf 或 httpd-vhosts.conf 中的 <Directory> 區塊若仍為:

<Directory "D:/www">
    Require all denied
</Directory>

或是缺少授權指令,Apache 會拒絕所有請求。

修正方法

在對應的 <Directory> 區塊中設定:

<Directory "D:/www">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

常見授權模式

需求指令範例
允許所有 IPRequire all granted
僅允許特定 IP/網段Require ip 192.168.1.0/24 10.0.0.1
僅允許特定主機名Require host example.com
組合條件 (全部滿足)<RequireAll> Require ip 192.168.1.0/24 Require user admin </RequireAll>
組合條件 (任一滿足)<RequireAny> Require ip 192.168.1.0/24 Require user admin </RequireAny>

WAMP / XAMPP 快速修改位置

  • WAMP:左鍵圖示 → Apache → httpd.conf,搜尋 <Directory "${INSTALL_DIR}/www/"> 區塊修改。
  • XAMPP:apache/conf/httpd.conf 或 apache/conf/extra/httpd-vhosts.conf 中的虛擬主機 <Directory> 區塊。

驗證生效

  1. 儲存配置後重啟 Apache 服務。
  2. 瀏覽器訪問站點根目錄,應不再出現 403。
  3. 若仍失敗,檢查錯誤日誌 logs/error.log 確認是否為其他模組(如 mod_security、mod_evasive)攔截。

只需將舊版 Order/Deny/Allow 替換為 Require all granted,即可解決絕大多數 Apache 2.4 遷移後的權限問題。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved