Nginx的目录文件列表功能,和自定义header和footer

30 篇文章 0 订阅

ngx_http_autoindex_module  此模块用于自动生成目录列表,ngx_http_autoindex_module只在 ngx_http_index_module模块未找到索引文件时发出请求.

nginx默认是不允许列出整个目录的。

开启目录列表:
打开nginx.conf文件,在location server 或 http段中加入
 autoindex on;

另外两个参数最好也加上去:
autoindex_exact_size off;
默认为on,显示出文件的确切大小,单位是bytes。
改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
autoindex_localtime on;
默认为off,显示的文件时间为GMT时间。
 改为on后,显示的文件时间为文件的服务器时间

配置Nginx目录列表的方法详细参照:http://wiki.nginx.org/NginxChsHttpAutoindexModule

如果想希望目录列表支持header,footer则可以安装三方插件: http://wiki.nginx.org/NginxNgxFancyIndex

Requirements

  • Sources for Nginx_ 0.8.x, and its requirements.
    • The module compiles with 0.7.x versions as well.
    • It _might_ compile with 0.6.x applying "nginx-0.6-support.patch", YMMV.
  • Patience, and some Coffee™.

Building

1. Unpack the Nginx_ sources::

   $ gunzip -c nginx-?.?.?.tar.gz | tar -xvf -

2. Download the latest version using Git:

   $ git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex

3. Change to the directory which contains the Nginx_ sources, run the

  configuration script with the desired options and be sure to put an
  ``--add-module`` flag pointing to the directory which contains the source
  of the fancy indexing module::
   $ cd nginx-?.?.?
   $ ./configure --add-module=../ngx-fancyindex  [extra desired options]

4. Build and install the software::

   $ make
  And then, as ``root``::
   # make install

5. Configure Nginx_ by using the modules' configuration directives_.

Example Enable

You can test the default built-in style by adding the following lines into a ``server`` section in your Nginx_ configuration file::

 location / {
   fancyindex on;              # Enable fancy indexes.
   fancyindex_exact_size off;  # Output human-readable file sizes.
 }


Directives

fancyindex

Syntax: *fancyindex* [*on* | *off*]
Default: fancyindex off
Context: http, server, location
Description:
 Enables or disables fancy directory indexes.

fancyindex_css_href

Syntax: *fancyindex_css_href uri*
Default: fancyindex_css_href ""
Context: http, server, location
Description:
 Allows inserting a link to a CSS style sheet in generated listings. The
 provided *uri* parameter will be inserted as-is in a ``<link>`` HTML tag.
 The link is inserted after the built-in CSS rules, so you can override the
 default styles.

fancyindex_exact_size

Syntax: *fancyindex_exact_size* [*on* | *off*]
Default: fancyindex_exact_size on
Context: http, server, location
Description:
 Defines how to represent file sizes in the directory listing; either
 accurately, or rounding off to the kilobyte, the megabyte and the
 gigabyte.

fancyindex_footer

Syntax: *fancyindex_footer path*
Default: fancyindex_footer ""
Context: http, server, location
Description:
 Specifies which file should be inserted at the foot of directory listings.
 If set to an empty string, the default footer supplied by the module will
 be sent.

.. warning:: When inserting custom header/footer a subrequest will be

  issued so potentially any URL can be used as source for them. Although it
  will work with external URLs, only using internal ones is supported.
  External URLs are totally untested and using them will make Nginx_ block
  while waiting for the subrequest to complete. If you feel like external
  header/footer is a must-have for you, please
  `let me know <mailto:aperez@igalia.com>`__.

fancyindex_header

Syntax: *fancyindex_header path*
Default: fancyindex_header ""
Context: http, server, location
Description:
 Specifies which file should be inserted at the head of directory listings.
 If set to an empty string, the default header supplied by the module will
 be sent.

fancyindex_ignore

Syntax: *fancyindex_ignore string1 [string2 [... stringN]]*
Default: No default.
Context: http, server, location
Description:
 Specifies a list of file names which will be not be shown in generated
 listings. If Nginx was built with PCRE support strings are interpreted as
 regular expressions.

fancyindex_localtime

Syntax: *fancyindex_localtime* [*on* | *off*]
Default: fancyindex_localtime off
Context: http, server, location
Description:
 Enables showing file times as local time. Default is “off” (GMT time).

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

anssummer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值