Fancy Index 模块使得生成文件列表成为可能,类似于内置的 autoindex 模块,但添加了一些样式。该模块允许一定程度上的内容自定义:
此模块设计用于与 Nginx_ 高性能开源 Web 服务器配合使用,该服务器由 Igor Sysoev 编写。
对于使用官方稳定版 Nginx 仓库的用户,提供了包含动态模块的额外包仓库,并且其中包含 fancyindex 模块。
直接安装:
yum install https://extras.getpagespeed.com/redhat/7/x86_64/RPMS/nginx-module-fancyindex-1.12.0.0.4.1-1.el7.gps.x86_64.rpm
或者,先添加额外仓库(以便未来更新),然后安装模块:
yum install nginx-module-fancyindex
然后在 /etc/nginx/nginx.conf 中加载模块:
load_module "modules/ngx_http_fancyindex_module.so";
在大多数其他情况下,您需要 Nginx_ 的源代码。任何从 0.8 系列开始的版本都应该可以工作。
为了使用 fancyindex_header 和 fancyindex_footer 指令,您还需要将 ngx_http_addition_module 构建到 Nginx 中。
解压 Nginx_ 源代码:
$ gunzip -c nginx-?.?.?.tar.gz | tar -xvf -
解压 fancy index 模块的源代码:
$ gunzip -c nginx-fancyindex-?.?.?.tar.gz | tar -xvf -
进入包含 Nginx_ 源代码的目录,运行配置脚本并指定所需的选项,确保添加一个指向 fancy index 模块源代码目录的 --add-module 标志:
$ cd nginx-?.?.?
$ ./configure --add-module=../nginx-fancyindex-?.?.? \
[--with-http_addition_module] [其他所需选项]
从版本 0.4.0 开始,该模块也可以作为动态模块构建,使用 --add-dynamic-module=… 并在配置文件中添加 load_module "modules/ngx_http_fancyindex_module.so";
构建并安装软件:
$ make
然后,以 root 用户身份运行:
# make install
使用模块的配置指令_ 配置 Nginx_。
您可以通过在 Nginx_ 配置文件中的 server 部分添加以下行来测试默认的内置样式:
location / { fancyindex on; # 启用 fancy indexes fancyindex_exact_size off; # 输出人类可读的文件大小 }
以下主题展示了使用该模块可以实现的自定义程度:
fancyindex [on | off]fancyindex offfancyindex_default_sort [name | size | date | name_desc | size_desc | date_desc]fancyindex_default_sort namefancyindex_directories_first [on | off]fancyindex_directories_first onfancyindex_css_href urifancyindex_css_href ""uri 参数会原样插入到 <link> HTML 标签中,链接插入在内置 CSS 规则之后,以便覆盖默认样式。fancyindex_exact_size [on | off]fancyindex_exact_size onfancyindex_name_length lengthfancyindex_name_length 50fancyindex_footer path [subrequest | local]fancyindex_footer ""path 是否应被当作使用子请求加载的 URI(默认情况),还是引用本地文件。fancyindex_header path [subrequest | local]fancyindex_header ""path 是否应被当作使用子请求加载的 URI(默认情况),还是引用本地文件。fancyindex_show_path [on | off]fancyindex_show_path on</h1> 标签,当希望用 PHP 脚本处理路径显示时很有用。fancyindex_show_dotfiles [on | off]fancyindex_show_dotfiles offfancyindex_ignore string1 [string2 [... stringN]]fancyindex_hide_symlinks [on | off]fancyindex_hide_symlinks offfancyindex_hide_parent_dir [on | off]fancyindex_hide_parent_dir offfancyindex_localtime [on | off]fancyindex_localtime offfancyindex_time_format stringfancyindex_time_format "%Y-%b-%d %H:%M"strftime 函数支持的子集,其行为与区域设置无关(例如,星期几和月份名称始终为英文)。:::tip 支持的时间格式说明符:
%a: 星期几的缩写名称。%A: 星期几的完整名称。%b: 月份的缩写名称。%B: 月份的完整名称。%d: 月份中的日期(范围 01 到 31)。%e: 类似于 %d,月份中的日期,但前导零被空格替换。%F: 等同于 %Y-%m-%d(ISO 8601 日期格式)。%H: 24 小时制的小时数(范围 00 到 23)。%I: 12 小时制的小时数(范围 01 到 12)。%k: 24 小时制的小时数(范围 0 到 23);单个数字前有空格。%l: 12 小时制的小时数(范围 1 到 12);单个数字前有空格。%m: 月份的数字(范围 01 到 12)。%M: 分钟数(范围 00 到 59)。%p: 根据给定的时间值,显示 "AM" 或 "PM"。%P: 类似于 %p,但小写: "am" 或 "pm"。%r: 上午或下午的时间表示法。等同于 %I:%M:%S %p。%R: 24 小时制的时间表示法(%H:%M)。%S: 秒数(范围 00 到 60)。%T: 24 小时制的时间表示法(%H:%M:%S)。%u: 星期几的数字,范围 1 到 7,周一为 1。%w: 星期几的数字,范围 0 到 6,周一为 0。%y: 不带世纪的年份数字(范围 00 到 99)。%Y: 带世纪的年份数字。template.html后生成新的头文件awk -f template.awk template.html > template.h