萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

Apache 403 Forbidden 錯誤完整解決方案

瀏覽器顯示 403 Forbidden: You don't have permission to access / on this server,核心原因通常是 Apache 存取控制與目錄索引設定不當。

一、修正目錄存取權限 (httpd.conf)

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all    # 預設為 Deny from all,改為 Allow
    Satisfy all
</Directory>

Order deny,allow 配合 Allow from all 表示「先檢查 deny,無匹配則允許」。預設 Deny from all 會封鎖所有請求。

二、確保目錄索引檔案存在

Apache 預設尋找 DirectoryIndex index.html。若目錄無索引檔且未啟用 Options Indexes,將回傳 403。

<IfModule dir_module>
    DirectoryIndex index.html index.php index.jsp
</IfModule>

三、啟用目錄瀏覽 (可選)

Options Indexes FollowSymLinks

加入 Indexes 允許使用者瀏覽目錄列表。

四、檔案系統權限同步檢查

即使 Apache 允許,若 Linux 檔案權限為 700 或擁有者非 apache/www-data,仍會 403。執行:

chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html

依序驗證:Apache 設定 → 索引檔 → 檔案權限,即可徹底消除 403。

copyright © 萬盛學電腦網 all rights reserved