一.ngx-fancyindex模块的简介:

     Nginx Web 服务器自带的目录浏览功能看起来并不是那么的美观,我们可以使用ngx-fancyindex插件来美化目录浏览功能。

     我们到https://github.com/aperezdc/ngx-fancyindex 下载ngx-fancyindex

二.在未安装nginx的情况下安装nginx第三方模块:

    # tar xf nginx-1.8.0.tar.gz 

    # unzip ngx-fancyindex-master.zip

    # cd nginx-1.8.0/

    # ./configure  --prefix=/usr/local/nginx --with-http_stub_status_module  --with-http_p_w_picpath_filter_module  --user=nginx --group=nginx --with-http_ssl_module --add-module=../ngx-fancyindex-master

PS: --add-module=第三方模块的解压目录路径

     # make && make install

三. 在已经安装nginx的情况下安装ngx-fancyindex模块:

     # tar xf nginx-1.8.0.tar.gz 

     # unzip ngx-fancyindex-master.zip

     # cd nginx-1.8.0/

     # ./configure  --prefix=/usr/local/nginx --with-http_stub_status_module  --with-http_p_w_picpath_filter_module  --user=nginx --group=nginx --with-http_ssl_module --add-module=../ngx-fancyindex-master

      # make                                                         ##不要make install

      # cp /objs/nginx  /usr/local/nginx/sbin/     ##复制重新编译的nginx文件到nginx原来安装目录下

PS:  安装nginx的第三方模块实际上是使用--add-module重新安装一次nginx,不要make install而是直接把编译目录下objs/nginx文件直接覆盖老的nginx文件.如果你需要安装多个nginx第三方模块,你只需要多指定几个相应的--add-module即可.重新编译的时候,记得一定要把以前编译过的模块一同加到configure参数里面.

       nginx提供了非常多的nginx第三方模块提供安装,地址http://wiki.nginx.org/3rdPartyModules

四.ngx-fancyindex配置

location  /ftp  {
         fancyindex on;
         fancyindex_exact_size off;
         fancyindex_localtime on;
         fancyindex_footer   "footer.html";
         auth_basic            "Restricted";
         auth_basic_user_file  "/etc/nginx/.htpasswd";
}

       fancyindex on:  是否开启fancyindex索引
       fancyindex_exact_size off: : 不使用精确的大小,使用四舍五入,1.9M会显示为2M这样.如果开启的话,单位为字节
       fancyindex_localtime on:  使用本地时间
       fancyindex_footer "footer.html":  把当前路径下的footer.html内容作为底部.

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样式。

      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打头的文件或目录以及文件file1.txt,配置如下:
     fancyindex_ignore "dir*" "file1.txt"

     fancyindex_localtime

     语法: *fancyindex_localtime* [*on* | *off*]
     默认值: fancyindex_localtime off
     配置块: http, server, location
     描述: 使用当地时间显示文件的创建时间,默认是off(GMT时间)