- 目录
- mod_dirlisting - 目录列表
- 描述
- 快速开始
- 性能
- JSON 列表
- 选项
- dir-listing.activate
- dir-listing.sort
- dir-listing.cache
- dir-listing.hide-dotfiles
- dir-listing.external-css
- dir-listing.external-js
- dir-listing.exclude
- dir-listing.encoding
- dir-listing.show-readme
- dir-listing.hide-readme-file
- dir-listing.show-header
- dir-listing.hide-header-file
- dir-listing.set-footer
- dir-listing.encode-header
- dir-listing.encode-readme
- dir-listing.auto-layout
- 表格排序
- CSS 示例
mod_dirlisting - 目录列表¶
描述¶
mod_dirlisting 会创建一个 HTML 页面,列出目标目录的内容。
mod_dirlisting 默认禁用;要启用它,请使用:dir-listing.activate = "enable"
虽然 lighttpd 提供了一些选项来调整目录列表的生成方式,但没有一种“一劳永逸”的解决方案。如果您需要自定义内容,则可以使用自定义生成器(例如,使用 Python 或 PHP)而不是使用 mod_dirlisting。
快速开始¶
当请求目录且在该目录中未找到索引文件时,会生成目录列表。
全局启用目录列表
dir-listing.activate = "enable"
如果您只需要针对特定目录或多个目录启用,请使用条件语句
$HTTP["url"] =~ "^/download($|/)" {
dir-listing.activate = "enable"
}
性能¶
创建目录列表可能开销很大,会占用 CPU 和内存,并且比提供静态文件花费更多时间,尤其是在大型目录上。如果目标目录不经常更改,那么使用 mod_indexfile 而不是 mod_dirlisting 会效率更高。如果使用 mod_indexfile,您可以在目录内容更改时(例如发布新版本的网站时)通过外部进程生成 index.html
。
自 lighttpd 1.4.60 起,可以使用一个选项来配置 mod_dirlisting,使其将目录列表缓存一小段时间,以减少在缓存期内生成目录列表的次数。dir-listing.cache = ( "path" => "/path/to/dirlist-cache", "max-age" => 15 )
如果未另行指定,默认缓存期为 15 秒("max-age" => 15
)。
自 lighttpd 1.4.74 起,可以使用一个选项来配置 mod_dirlisting,使其禁用目录的服务器端排序,从而允许客户端 JavaScript(如果启用)在显示之前在客户端对列表进行排序。
@dir-listing.sort = "disable"
另一个选项是配置 mod_indexfile 来生成目录列表并可能缓存结果。index-file.names = ( "/dir-generator.php" )
如果请求目录,则会调用 dir-generator.php
,该文件可以获取 REQUEST_URI 以查看请求了哪个目录。请注意,目标 dir-generator 路径必须存在于文件系统中,否则 mod_indexfile 将跳过它。(换句话说,dir-generator.php
必须存在,即使是一个空文件,对于 mod_indexfile 也是如此,即使目标由 mod_fastcgi 或 mod_scgi 处理并配置为 "check-local" => "disable")。
dir-generator.php
文件可以在本文档底部找到,最初由 http://www.archerseven.com/kittykatt/index.php?page=scripts&sub=lighttpdlisting 贡献。
JSON 列表¶
使用 lighttpd 1.4.72 及更高版本,如果请求包含查询字符串 ?json
,mod_dirlisting 可以生成 JSON 输出。https://example.org/path/to/dir/?json
选项¶
dir-listing.activate¶
如果请求目录且未找到索引文件,则启用虚拟目录列表。
默认值:禁用
dir-listing.sort¶
(自 1.4.74 起)控制页面提供之前在服务器上对目录列表进行字母排序。
历史上,mod_dirlisting 在客户端未启用 JavaScript 的情况下会在服务器上对结果进行排序。
此配置选项允许在服务器上禁用目录排序。
(如果启用 JavaScript,它仍然可以在显示页面之前在客户端对目录列表进行排序)
在低资源系统上,如果服务包含大量条目的目录,建议禁用此功能。
默认值:启用
dir-listing.cache¶
默认值:无(禁用)
自 lighttpd 1.4.60 起,mod_dirlisting 可以配置为将目录列表缓存一小段时间,以减少在缓存期内生成目录列表的次数。dir-listing.cache = ( "path" => "/path/to/dirlist-cache", "max-age" => 15 )
如果未另行指定,默认缓存期为 15 秒("max-age" => 15
)。
dir-listing.hide-dotfiles¶
如果启用,则不会列出由 dir-listing 选项生成的目录列表中的隐藏文件。
默认值:启用
dir-listing.external-css¶
用于目录列表的外部 CSS 样式表的 URL。
dir-listing.external-js¶
外部 JS 脚本的 URL,例如用于客户端目录列表排序(lighttpd 1.4.42)
dir-listing.exclude¶
正则表达式列表。与任何指定正则表达式匹配的文件都将从目录列表中排除。
在 1.4.14 之前,在条件语句中使用此功能存在问题。请参阅 #1260。
dir-listing.encoding¶
为生成的目录列表设置编码。
如果您的文件系统没有使用 ASCII,则必须设置文件名编码,因为它们会按原样放入 HTML 列表中(带 XML 编码)。
示例
dir-listing.encoding = "utf-8"
默认值
dir-listing.encoding = "iso-8859-1"
dir-listing.show-readme¶
在目录列表后显示 README.txt 文件的内容。
(自 1.4.43 起,可以是用户指定的文件名,而不是 README.txt)
(自 1.4.46 起,以“/”开头的路径被视为文件系统中的绝对路径)
默认值:禁用
dir-listing.hide-readme-file¶
从目录列表中隐藏 README.txt 文件。
默认值:禁用
dir-listing.show-header¶
在目录列表之前显示 HEADER.txt 文件的内容。
(自 1.4.43 起,可以是用户指定的文件名,而不是 HEADER.txt)
(自 1.4.46 起,以“/”开头的路径被视为文件系统中的绝对路径)
默认值:禁用
dir-listing.hide-header-file¶
从目录列表中隐藏 HEADER.txt 文件。
默认值:禁用
dir-listing.set-footer¶
在列表页面的页脚显示一个字符串。
默认值:"<PACKAGE_NAME>/<PACKAGE_VERSION>" 即 "lighttpd/1.4.18"
以下 3 个选项自 1.4.23 版本起可用:¶
dir-listing.encode-header¶
此选项是一个布尔值。
它提供了将有效 HTML 文件作为 HEADER.txt 提供能力,此文件仅在实际列表之前打印。另请参阅 dir-listing.encode-readme。
默认值:启用
dir-listing.encode-readme¶
此选项是一个布尔值。
它提供了将有效 HTML 文件作为 README.txt 提供能力,此文件仅在实际列表之后打印。另请参阅 dir-listing.encode-header。
默认值:启用
dir-listing.auto-layout¶
此选项是一个布尔值。
禁用时,它将删除 lighttpd 自动输出的页面开头和结尾的 HTML 部分(从 <DOCTYPE 到 <body> 以及 </body></html>)。这使得可以在 header 和 readme 文件中处理这些部分。
默认值:启用
表格排序¶
自 lighttpd 1.4.42 起,包含了一组默认的 JavaScript,以启用目录列表表格排序(只要 dir-listing.auto-layout = "enable"
是默认设置,并且 JavaScript 未被 dir-listing.external-js
指定的自定义代码替换)。
Apache autoindex 请求查询参数 (https://httpd.apache.ac.cn/docs/current/en/mod/mod_autoindex.html) 的部分实现可用于影响目录内容的初始排序方式。
如果在 dir-listing 的 URL 请求中提供了查询字符串,则允许指定初始排序列- ?C=N 名称(默认)
- ?C=M 最后修改时间,然后按名称
- ?C=S 大小,然后按名称
- ?C=T 类型,然后按名称
- ?C=D 类型,然后按名称
- ?C=N&O=D 降序(默认)
- ?C=N&O=A 升序
CSS 示例¶
dir-listing.external-css = "..."
可用于指定 mod_dirlisting 包含的替代 CSS
lighttpd mod_dirlisting 默认样式表参数(如果未配置 dir-listing.external-css
)
a, a:active {text-decoration: none; color: blue;} a:visited {color: #48468F;} a:hover, a:focus {text-decoration: underline; color: red;} body {background-color: #F5F5F5;} h2 {margin-bottom: 12px;} table {margin-left: 12px;} th, td {font: 90% monospace; text-align: left;} th {font-weight: bold; padding-right: 14px; padding-bottom: 3px;} td {padding-right: 14px;} td.s, th.s {text-align: right;} div.list {background-color: white; border-top: 1px solid #646464; border-bottom: 1px solid #646464; padding-top: 10px; padding-bottom: 14px;} div.foot {font: 90% monospace; color: #787878; padding-top: 4px;}
用户贡献的目录列表 CSS (by lucianor) (https://github.com/lighttpd/lighttpd1.4/pull/126)
a, a:active {text-decoration: none; color: blue;} a:visited {color: #48468F;} a:hover, a:focus {text-decoration: underline; color: red;} body {background-color: #F5F5F5;} h2 {margin-bottom: 12px;} table {margin-left: 12px; max-width: 100%; width: 100%; margin-bottom: 20px; background-color: #ffffff;} table > thead > tr > th, table > tbody > tr > th, table > tfoot > tr > th, table > thead > tr > td, table > tbody > tr > td, table > tfoot > tr > td {padding: 8px; line-height: 1.42; vertical-align: top; border-top: 1px solid #dddddd;} table > thead > tr > th {vertical-align: bottom; border-bottom: 2px solid #dddddd;} table > tbody + tbody {border-top: 2px solid #dddddd;} th, td {font: 90% monospace; text-align: left;} th {font-weight: bold; padding-right: 14px; padding-bottom: 3px;} td {padding-right: 14px;} td.s, th.s {text-align: right;} div.list {background-color: white; border-top: 1px solid #646464; border-bottom: 1px solid #646464; padding-top: 10px; padding-bottom: 14px;} div.foot {font: 90% monospace; color: #787878; padding-top: 4px;}