為了簡單共享文件,有些人使用svn,有些人使用ftp,但是更多得人使用索引(index)功能。apache得索引功能強大,并且也是最常見得,nginx的auto_index實現得目錄索引偏少,而且功能非常簡單。先來看看我們得效果圖。
nginx配置
location ~ ^/2589(/.*) { autoindex on; //開啟 autoindex_localtime on;//開啟顯示功能 }
auto_index指令
語法: autoindex on | off;
配置段: autoindex off;
配置段: http, server, location
啟用/僅用nginx目錄索引功能.
語法: autoindex_exact_size on | off;
配置段:autoindex_exact_size on;
配置段: http, server, location
制定是否額外得顯示文件得大小,單位為字節,mb,gb等等. 默認是打開得
syntax: autoindex_localtime on | off;
配置段: autoindex_localtime off;
配置段: http, server, location
指定是否顯示目錄或者文件得時間,默認是不顯示。
nginx+fancy實現漂亮的索引目錄
nginx索引目錄自帶的功能很簡單,而且不好看,如何做一個漂亮的索引列表.接下來看.
安裝環境
系統:centos 6.3nginx:1.4.2
fancy: http://wiki.nginx.org/NgxFancyIndex
下載安裝fancy
對比一下nginx內置的index效果(上篇文章貼過來的圖),如下
# wget http://gitorious.org/ngx-fancyindex/ngx-fancyindex/archive-tarball/master# tar -xzvf master# wget http://nginx.org/download/nginx-1.4.2.tar.gz# tar -xzvf nginx-1.4.2.tar.gz# cd nginx-1.4.2# ./configure --prefix=/usr/local/nginx-1.4.2 --add-module=../ngx-fancyindex-ngx-fancyindex# make# make install
fancy索引配置
server {listen 80; server_name test.vevb.com; access_log /data/logs/nginx/test.vevb.com.access.log main;index index.html index.php index.html; root /data/site/test.vevb.com;location / {} location ~ ^/2589(/.*) { fancyindex on; fancyindex_exact_size off; fancyindex_localtime on; fancyindex_footer "myfooter.shtml"; } }
看看nginx加了fancy的效果,如下圖.
比自帶的好看多少,這個不好說...反正就是....變好看了點~
參數解釋:
fancyindex on:開啟fancy索引
fancyindex_exact_size off:不使用精確的大小,使用四舍五入,1.9M會顯示為2M這樣.如果開啟的話,單位為字節
fancyindex_localtime on:使用本地時間
fancyindex_footer "myfooter.shtml":把當前路徑下的myfooter.shtml內容作為底部.文件不存在底部會出現404
myfooter.shtml內容如下:
<!-- footer START --> <div id="footer"> <a id="gotop" href="#" onclick="MGJS.goTop();return false;">回到頂部</a> <a id="powered" href="http://wordpress.org/">WordPress</a> <div id="copyright"> 版權所有 © 2006-2015 VEVB武林網 </div> <div id="themeinfo"> <a href="http://www.49028c.com/about/">關于我們</a> | <a href="http://www.49028c.com/sitemap.html">網站導航</a> | <a href="http://www.49028c.com/sitemap.xml">網站地圖</a> |<a rel="nofollow" href="http://www.miibeian.gov.cn/">蘇ICP備14036222號</a> </div> </div> <!-- footer END -->fancy指令使用:
fancyindex
語法:
*fancyindex* [*on* | *off*]
默認值: fancyindex off
配置塊: http, server, location
描述: 開啟/關閉目錄索引功能
fancyindex_css_href
語法:
*fancyindex_css_href uri*
默認值: fancyindex_css_href ""
配置塊: http, server, location
描述: 外置css路徑,這個css將會替代掉現有的css樣式。如果你會css,那你可以把索引列表做得更加漂亮.咱們ttlsa沒有網頁設計師,所以只能用自帶的了^^
fancyindex_exact_size
語法:
*fancyindex_exact_size* [*on* | *off*]
默認值: fancyindex_exact_size on
配置塊: http, server, location
描述: 定義如何顯示文件的大小,默認是on,on:文件大小使用精確值,單位為字節.off:單位為KB,MB,GB,如果含有小數點,將會四舍五入。例如1.9MB,將會顯示為2MB。
fancyindex_footer
語法:
*fancyindex_footer path*
默認值: fancyindex_footer ""
配置塊: http, server, location
描述: 指定哪個文件嵌入到索引頁面的底部,效果請看本文的第一張圖片
fancyindex_header
語法:
*fancyindex_header path*
默認值: fancyindex_header ""
配置塊: http, server, location
描述: 指定哪個文件嵌入到索引頁面的頭部.用法和fancyindex_footer類似
fancyindex_ignore
語法:
*fancyindex_ignore string1 [string2 [... stringN]]*
默認值: No default.
配置塊: http, server, location
描述: 哪些文件/目錄隱藏掉,如果你的nginx支持正則,那么可以使用正則表達式來過濾
例如我想隱藏dir打頭的文件或目錄以及文件filea.txt,配置如下:
fancyindex_ignore "dir*" "filea.txt"
fancyindex_localtime
語法:
*fancyindex_localtime* [*on* | *off*]
默認值: fancyindex_localtime off
配置塊: http, server, location
Description: 使用當地時間顯示文件的創建時間,默認是off(GMT時間)