Nginx ngx-fancyindex插件安装
Nginx Web 服务器自带的目录浏览功能看起来并不是那么的美观,我们可以使用ngx-fancyindex插件来美化目录浏览功能。
首先下载nginx,下载地址:http://nginx.org/download/,选择合适的版本进行下载即可
我们到https://github.com/aperezdc/ngx-fancyindex 下载ngx-fancyindex
命令:wget https://github.com/aperezdc/ngx-fancyindex/archive/master.zip
下载nginx安装包,wget http://nginx.org/download/nginx-1.5.9.tar.gz,注:这里下载的是1.5.9版本,可根据服务器上Nginx的版本进行下载。
具体操作步骤:
- 解压缩Nginx及ngx-fancyindex压缩包
- 获取Nginx原有编辑配置
- 编译及安装ngx-fancyindex插件
- 配置ngx-fancyinde插件
tar -zxvf master.zip /soft/nginx/ngx-fancyindex tar -zxvf nginx-1.5.9.tar.gz /soft/nginx
获取Nginx原有编译配置
# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.2.7 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6
重新编译Nginx以及ngx-fancyindex-master模块
#./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --add-module=./ngx-fancyindex-master
make && make install
配置ngx-fancyindex插件
在.conf文件中添加如下:
location /{ fancyindex on; fancyindex_exact_size off; fancyindex_localtime on; fancyindex_footer footer.html; fancyindex_header header.html; fancyindex_ignore footer.html header.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样式。如果你会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时间)
『—ENDOF—』