Nginx服務器下配置使用索引目錄的教程
為了簡單共享文件,有些人使用svn,有些人使用ftp,但是更多得人使用索引(index)功能。apache得索引功能強大,并且也是最常見得,nginx的auto_index實現(xiàn)得目錄索引偏少,而且功能非常簡單。先來看看我們得效果圖。
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
制定是否額外得顯示文件得大小,單位為字節(jié),mb,gb等等. 默認是打開得
syntax: autoindex_localtime on | off;
配置段: autoindex_localtime off;
配置段: http, server, location
指定是否顯示目錄或者文件得時間,默認是不顯示。
nginx+fancy實現(xiàn)漂亮的索引目錄
nginx索引目錄自帶的功能很簡單,而且不好看,如何做一個漂亮的索引列表.接下來看.
安裝環(huán)境
系統(tǒng):centos 6.3nginx:1.4.2
fancy: http://wiki.nginx.org/NgxFancyIndex
下載安裝fancy
對比一下nginx內(nèi)置的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.jb51.net; access_log /data/logs/nginx/test.jb51.net.access.log main; index index.html index.php index.html; root /data/site/test.jb51.net; location / { } location ~ ^/2589(/.*) { fancyindex on; fancyindex_exact_size off; fancyindex_localtime on; fancyindex_footer "myfooter.shtml"; } }
看看nginx加了fancy的效果,如下圖.
比自帶的好看多少,這個不好說...反正就是....變好看了點~
參數(shù)解釋:
fancyindex on:開啟fancy索引
fancyindex_exact_size off:不使用精確的大小,使用四舍五入,1.9M會顯示為2M這樣.如果開啟的話,單位為字節(jié)
fancyindex_localtime on:使用本地時間
fancyindex_footer "myfooter.shtml":把當前路徑下的myfooter.shtml內(nèi)容作為底部.文件不存在底部會出現(xiàn)404
myfooter.shtml內(nèi)容如下:
<!-- footer START --> <div id="footer"> <a id="gotop" href="#" onclick="MGJS.goTop();return false;">回到頂部</a> <a id="powered" >WordPress</a> <div id="copyright"> 版權(quán)所有 © 2006-2015 腳本之家 </div> <div id="themeinfo"> <a href="http://www.dbjr.com.cn/about/">關(guān)于我們</a> | <a href="http://www.dbjr.com.cn/sitemap.html">網(wǎng)站導航</a> | <a href="http://www.dbjr.com.cn/sitemap.xml">網(wǎng)站地圖</a> |<a rel="nofollow" >蘇ICP備14036222號</a> </div> </div> <!-- footer END --> fancy指令使用:
fancyindex
語法:
*fancyindex* [*on* | *off*]
默認值: fancyindex off
配置塊: http, server, location
描述: 開啟/關(guān)閉目錄索引功能
fancyindex_css_href
語法:
*fancyindex_css_href uri*
默認值: fancyindex_css_href ""
配置塊: http, server, location
描述: 外置css路徑,這個css將會替代掉現(xiàn)有的css樣式。如果你會css,那你可以把索引列表做得更加漂亮.咱們ttlsa沒有網(wǎng)頁設計師,所以只能用自帶的了^^
fancyindex_exact_size
語法:
*fancyindex_exact_size* [*on* | *off*]
默認值: fancyindex_exact_size on
配置塊: http, server, location
描述: 定義如何顯示文件的大小,默認是on,on:文件大小使用精確值,單位為字節(jié).off:單位為KB,MB,GB,如果含有小數(shù)點,將會四舍五入。例如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: 使用當?shù)貢r間顯示文件的創(chuàng)建時間,默認是off(GMT時間)
相關(guān)文章
解決nginx“504?Gateway?Time-out”錯誤
這篇文章介紹了解決nginx“504?Gateway?Time-out”錯誤的方法,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-12-12Nginx重定向后請求參數(shù)丟失的原因分析及解決方案
在日常開發(fā)和運維中,我們經(jīng)常會遇到需要使用 Nginx 進行反向代理的場景,但在配置 proxy_pass 時,有時候可能會遇到請求參數(shù)丟失的問題,在這篇文章中,我們將會詳細探討這個問題并給出幾種解決方案,需要的朋友可以參考下2023-11-11Nginx使用自簽ssl證書實現(xiàn)https連接的方法
本文主要介紹了Nginx使用自簽ssl證書實現(xiàn)https連接的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-07-07