Nginx ngx_http_autoindex_module 模組提供目錄列表功能,適合靜態檔案下載站、內部資源分享等場景。預設關閉,需顯式開啟。
| 指令 | 預設值 | 說明 |
|---|---|---|
autoindex | off | 開啟目錄列表功能 |
autoindex_exact_size | on | off 時以人類可讀單位(KB/MB/GB)顯示檔案大小 |
autoindex_localtime | off | on 時顯示伺服器本地時間,而非 GMT |
server {
listen 80;
server_name files.example.com;
root /var/www/files;
location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}
ngx_fancyindex 模組支援主題、排序、搜尋、面包屑導航allow/deny 或 auth_basic 限制存取權限autoindex_format json 搭配前端過濾,或用 location ~ /\. { deny all; } 隱藏隱藏檔open_file_cache 減少系統呼叫root 路徑正確、目錄執行權限(chmod +x)、SELinux/AppArmor 未阻擋charset utf-8;合理配置 autoindex 三大參數,即可快速建立功能完善、體驗友善的檔案瀏覽介面。