HTTP 403 表示伺服器理解請求但拒絕授權存取。非技術錯誤,屬存取控制決策結果。
autoindex off) 且無索引檔案時存取目錄。Nginx 執行身分 (通常 www-data、nginx) 需要:
範例:存取 /usr/local/nginx/html/image.jpg 需 image.jpg 644,且 /、/usr、/usr/local、/usr/local/nginx、/usr/local/nginx/html 皆為 755。
# 快速修正
find /path/to/web -type d -exec chmod 755 {} \;
find /path/to/web -type f -exec chmod 644 {} \;
# 錯誤配置:缺少 index.php
index index.html index.htm;
# 正確配置 (PHP 站點)
index index.html index.htm index.php;
若目錄下無 index.html/index.htm 且未列入 index.php,Nginx 直接回傳 403 而不嘗試 index.php。
同理,JSP/Python 站點需加入 index.jsp、index.py。
ps aux | grep nginx)。location 區塊 index 指令包含所有可能首頁檔名。error_log 確認具體拒絕原因 (permission denied / no index file)。httpd_read_user_content、httpd_enable_homedirs 等布林值。