將專案部署到 Apache HTTP Server 後,雖然 apachectl -t 檢測配置文件無誤,但瀏覽器訪問卻提示「You don't have permission to access / on this server」。這通常是權限配置問題,而非語法錯誤。以下提供系統性排查步驟。
首先查看 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。
Apache 運行用戶(httpd.conf 指定的 User/Group)必須擁有對網站目錄及所有父目錄的讀取與執行權限。參考 Apache Wiki PermissionDenied 說明:
644 (-rw-r--r--)755 (drwxr-xr-x)可用指令檢查並修復:
cd /var/www/html/your_project ls -l chmod 644 index.php # 對目錄及父目錄 ls -la chmod +x . cd .. # 重複至根目錄
或使用 namei -m /完整/路徑/檔案 快速定位權限缺失處。
若以上均正常,可能是 SELinux 阻擋。暫時關閉測試:
setenforce 0
若問題解決,請配置正確的 SELinux 上下文(如 httpd_sys_content_t)而非永久關閉。
建議由外而內逐層排查,通常在檔案系統權限或 SELinux 上找到癥結。
IIS 6.0 網站效能優化 13 大秘技:基於 YSlow 實戰調優
Windows 服務器組件安全加固策略:禁用高危 COM 組件與腳本防護
Linux Apache 啟動報錯 Internal Server Error:mod_rewrite 模組未載入解決方案
Linux 環境下 LAMP (Linux + Apache + MySQL + PHP) 完整編譯安裝指南
Apache HTTP Server 2.4 圖形化配置工具完整操作指南
Windows Server 2003 R2 關鍵技術全解析:分支辦公室、身分認證與儲存管理三大增強