命令 | 默認值 | 值域 | 作用域 | EG |
---|---|---|---|---|
autoindex | off | on:開啟目錄瀏覽;off:關閉目錄瀏覽 | http, server, location | autoindex on;打開目錄瀏覽功能 |
autoindex_format | html | html、xml、json、jsonp 分別用這幾個風格展示目錄 | http, server, location | autoindex_format html; 以網頁的風格展示目錄內容。該屬性在1.7.9及以上適用 |
autoindex_exact_size | on | on:展示文件字節數;off:以可讀的方式顯示文件大小 | http, server, location | autoindex_exact_size off; 以可讀的方式顯示文件大小,單位為 KB、MB 或者 GB,autoindex_format為html時有效 |
autoindex_localtime | off | on、off:是否以服務器的文件時間作為顯示的時間 | http, server, location | autoindex_localtime on; 以服務器的文件時間作為顯示的時間,autoindex_format為html時有效 |
完整配置如下:
location /download
{
root /home/map/www/; #指定目錄所在路徑
autoindex on; #開啟目錄瀏覽
autoindex_format html; #以html風格將目錄展示在瀏覽器中
autoindex_exact_size off; #切換為 off 后,以可讀的方式顯示文件大小,單位為 KB、MB 或者 GB
autoindex_localtime on; #以服務器的文件時間作為顯示的時間
charset utf-8,gbk; #展示中文文件名
}
目錄瀏覽美化
要查看Nginx編譯了哪些模塊,執行以下命令:
2>&1 nginx -V | tr ' ' '\n'|grep module
查看完整的編譯參數:nginx -V
動態編譯添加Nginx模塊
- 在GitHub下載最新源碼:ngx-fancyindex
- Nginx-Index源碼下載下來后,解壓,放到nginx源碼目錄(/usr/local/nginx)中,執行下面的代碼,編譯:
nginx -V
參數添加--add-module=ngx-fancyindex-0.4.2
make
這里不要 make install!!- 選擇Fancy Index主題 Nginx-Fancyindex-Theme
Fancy Index 配置
- 進入Nginx安裝的web目錄,執行nginx -V,輸出configure arguments: --prefix=/usr/local/nginx,就是這個目錄
- git clone https://github.com/lanffy/Nginx-Fancyindex-Theme.git
- 在nginx location模塊中添加Fancy Index配置,如下:
location /download
{
include /usr/local/nginx/html/Nginx-Fancyindex-Theme/fancyindex.conf; # 目錄美化配置
root /home/map/www/; #指定目錄所在路徑
autoindex on; #開啟目錄瀏覽
autoindex_format html; #以html風格將目錄展示在瀏覽器中
autoindex_exact_size off; #切換為 off 后,以可讀的方式顯示文件大小,單位為 KB、MB 或者 GB
autoindex_localtime on; #以服務器的文件時間作為顯示的時間
charset utf-8,gbk; #展示中文文件名
}
#fancyindex.conf
fancyindex on;
fancyindex_localtime on;
fancyindex_exact_size off;
fancyindex_header "/Nginx-Fancyindex-Theme/header.html";
fancyindex_footer "/Nginx-Fancyindex-Theme/footer.html";
# Ignored files will not show up in the directory listing, but will still be public.
fancyindex_ignore "examplefile.html";
# Making sure folder where files are don't show up in the listing.
fancyindex_ignore "Nginx-Fancyindex-Theme";
# Maximum file name length in bytes, change as you like.
fancyindex_name_length 255;