1.下載FancyIndex包:https://codeload.github.com/aperezdc/ngx-fancyindex/zip/master
2.將下載的zip包解壓到nginx源碼目錄
unzip ngx-fancyindex-master.zip
3.編輯安裝Nginx
yum -y install gcc-c++ yum -y install pcre-devel zlib-devel openssl-devel ./configure --prefix=/usr/local/nginx --add-module=./ngx-fancyindex-master make make install
4.下載fancyindex資源文件:https://github.com/TheInsomniac/Nginx-Fancyindex-Theme
5.下載后,解壓到站點根目錄
unzip Nginx-Fancyindex-Theme-master.zip mv Nginx-Fancyindex-Theme-master fancyindex
6.配置Nginx配置文件,在location或者server中添加以下代碼:
#autoindex on; #autoindex_exact_size off; #autoindex_localtime on; fancyindex on; fancyindex_localtime on; #on for local time zone. off for GMT fancyindex_exact_size off; #off for human-readable. on for exact size in bytes fancyindex_header "/fancyindex/header.html"; fancyindex_footer "/fancyindex/footer.html"; fancyindex_ignore "fancyindex"; #ignore this directory when showing list fancyindex_default_sort date_desc; #以上傳時間倒序排列
7.啟動nginx
/usr/local/nginx/sbin/nginx -s stop && /usr/local/nginx/sbin/nginx
8.自定義footer.html信息(可選)
<!-- 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"> 版權所有 © 本頁面由xxx提供 </div> <div id="themeinfo"> <a href="http://www.xxx.com/about/">關於我們</a> | <a href="http://www.xxx.com/sitemap.html">網站導航</a> | <a href="http://www.xxx.com/sitemap.xml">網站地圖</a> |<a rel="nofollow" href="http://www.xxx.com/">xxx公司</a> </div> </div> <!-- footer END -->
9.使用php動態頁面的nginx配置(可選)
root /share; index index.php; location / { charset utf-8; #autoindex on; #autoindex_exact_size off; #autoindex_localtime on; fancyindex on; fancyindex_localtime on; fancyindex_exact_size off; fancyindex_header "/fancyindex/header.php"; fancyindex_footer "/fancyindex/footer.php"; # fancyindex_ignore "fancyindex"; # fancyindex_default_sort date_desc; index index.php index.html index.htm; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /favicon.ico { log_not_found off; access_log off; }