Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Apache 403 Forbidden 錯誤排查:從目錄權限到 httpd.conf 核心配置

編輯:關於伺服器

現象與誤區

瀏覽器回傳「403 Forbidden:You don't have permission to access / on this server」,目錄 NTFS 權限已給 Everyone 完全控制,卻仍無法存取。問題核心在 Apache 配置而非檔案系統權限。

關鍵配置段落分析

全域預設拒絕規則

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
    Satisfy all
</Directory>

Deny from all 封鎖所有根目錄下的存取。直接改為 Allow from all 雖能通過,但會暴露整個檔案系統,極度危險。

正確做法:針對 DocumentRoot 精準授權

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
  • 將 Directory 路徑改為實際網站根目錄(DocumentRoot)
  • Order allow,deny + Allow from all:先評估允許規則,預設允許所有
  • Options Indexes FollowSymLinks:允許目錄列表與符號連結

操作步驟總結

  1. 開啟 httpd.conf,尋找 <Directory /> 區塊,確認 Deny from all 存在
  2. 尋找 DocumentRoot 對應的 <Directory> 區塊(或新增)
  3. 設定 Order allow,deny 與 Allow from all
  4. 重啟 Apache:systemctl restart httpd 或 apachectl restart
  5. 瀏覽器驗證存取正常

安全加固建議

  • 生產環境建議關閉 Indexes,防止目錄遍歷洩露檔案結構
  • 啟用 AllowOverride None 禁止 .htaccess 覆蓋,集中管控
  • 敏感目錄額外加入 Require ip 192.168.1.0/24 限制存取來源
Copyright © Windows教程網 All Rights Reserved