AutoIndex#
该模块处理以斜杠字符 (/) 结尾的请求,并生成目录列表。通常,当 Index 模块找不到索引文件时,请求会传递给 AutoIndex 模块。
当 从源代码构建 时,该模块默认会被构建;可以通过
构建选项 --without-http_autoindex_module 禁用它。
在来自 我们的软件仓库 的包和镜像中,该模块已包含在
构建中。 启用或禁用目录列表输出。 对于 HTML 格式,指定目录列表中是否输出精确的文件大小,或者将其四舍五入到千字节、兆字节和千兆字节。 设置目录列表的格式。 当使用 JSONP 格式时,回调函数的名称通过 XML 输出可以通过 XSLT 模块进行转换。 输出格式 响应中的对象字段包含以下数据: 字段 描述 文件或目录名称 对象类型: 文件大小,以字节为单位;对于目录则省略此字段。
autoindex_exact_size 仅影响 Unix 时间格式的最后修改时间 对于 HTML 格式,指定目录列表中的时间是以本地时区还是以 UTC 输出。配置示例#
location / {
autoindex on;
}
指令#
autoindex#
autoindex_exact_size#
autoindex_format#
callback 请求参数设置。如果参数缺失或为空值,则使用 JSON 格式。nametypefile 或 directorysizehtml 格式mtime<html>
<head>
<title>Index of /files/</title>
</head>
<body>
<h1>Index of /files/</h1>
<hr>
<pre>
<a href="../">../</a>
<a href="example.txt">example.txt</a> 12-Jun-2025 14:21 1234
<a href="image.png">image.png</a> 12-Jun-2025 14:21 4321
</pre>
<hr>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<listing>
<file>
<name>example.txt</name>
<type>file</type>
<size>1234</size>
<mtime>2025-06-12T14:21:00Z</mtime>
</file>
<file>
<name>image.png</name>
<type>file</type>
<size>4321</size>
<mtime>2025-06-12T14:21:00Z</mtime>
</file>
</listing>
[
{
"name": "example.txt",
"type": "file",
"size": 1234,
"mtime": "2025-06-12T14:21:00Z"
},
{
"name": "image.png",
"type": "file",
"size": 4321,
"mtime": "2025-06-12T14:21:00Z"
}
]
callback([
{
"name": "example.txt",
"type": "file",
"size": 1234,
"mtime": "2025-06-12T14:21:00Z"
},
{
"name": "image.png",
"type": "file",
"size": 4321,
"mtime": "2025-06-12T14:21:00Z"
}
]);
autoindex_localtime#