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

Apache「You don't have permission to access / on this server」錯誤完整解決指南

編輯:關於伺服器

將專案部署到 Apache HTTP Server 後,雖然 apachectl -t 檢測配置文件無誤,但瀏覽器訪問卻提示「You don't have permission to access / on this server」。這通常是權限配置問題,而非語法錯誤。以下提供系統性排查步驟。

1. 檢查目錄存取權限設定

首先查看 conf.d/python.conf(或對應的虛擬主機配置)中 <Directory> 區塊:

<Directory "專案路徑">
    Options Indexes FollowSymLinks +Includes
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

確認 Allow from all 存在,表示允許所有來源訪問。若使用 Apache 2.4+,需改為 Require all granted。

2. 核對檔案系統層級權限

Apache 運行用戶(httpd.conf 指定的 User/Group)必須擁有對網站目錄及所有父目錄的讀取與執行權限。參考 Apache Wiki PermissionDenied 說明:

  • 一般檔案權限應為 644 (-rw-r--r--)
  • 目錄與 CGI 腳本權限應為 755 (drwxr-xr-x)
  • 需逐級檢查至根目錄

可用指令檢查並修復:

cd /var/www/html/your_project
ls -l
chmod 644 index.php
# 對目錄及父目錄
ls -la
chmod +x .
cd ..
# 重複至根目錄

或使用 namei -m /完整/路徑/檔案 快速定位權限缺失處。

3. 檢查 SELinux 等擴展安全模組

若以上均正常,可能是 SELinux 阻擋。暫時關閉測試:

setenforce 0

若問題解決,請配置正確的 SELinux 上下文(如 httpd_sys_content_t)而非永久關閉。

常見原因總結

  • 配置文件允許訪問,但檔案系統權限不足
  • Apache 運行用戶無法遍歷父目錄
  • SELinux/AppArmor 策略阻擋

建議由外而內逐層排查,通常在檔案系統權限或 SELinux 上找到癥結。

Copyright © Windows教程網 All Rights Reserved