<!-- review: finished -->

<a id="http-autoindex"></a>

# AutoIndex

该模块处理以斜杠字符 (`/`) 结尾的请求，并生成目录列表。通常，当 [Index](https://cn.angie.software//angie/docs/configuration/modules/http/http_index.md#http-index) 模块找不到索引文件时，请求会传递给 `AutoIndex` 模块。

<a id="configuration-example-8"></a>

## 配置示例

```nginx
location / {
    autoindex on;
}
```

<a id="directives-9"></a>

## 指令

<a id="index-0"></a>

<a id="id3"></a>

### autoindex

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `autoindex` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `autoindex off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

启用或禁用目录列表输出。

<a id="index-1"></a>

<a id="autoindex-exact-size"></a>

### autoindex_exact_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `autoindex_exact_size` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `autoindex_exact_size on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

对于 HTML [格式](#autoindex-format)，指定目录列表中是否输出精确的文件大小，或者将其四舍五入到千字节、兆字节和千兆字节。

<a id="index-2"></a>

<a id="autoindex-format"></a>

### autoindex_format

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `autoindex_format` `html` | `xml` | `json` | `jsonp`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------|
| 默认值                                                                                  | `autoindex_format html;`                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                  |

设置目录列表的格式。

当使用 JSONP 格式时，回调函数的名称通过 `callback` 请求参数设置。如果参数缺失或为空值，则使用 JSON 格式。

XML 输出可以通过 [XSLT](https://cn.angie.software//angie/docs/configuration/modules/http/http_xslt.md#http-xslt) 模块进行转换。

### 输出格式

响应中的对象字段包含以下数据：

| 字段      | 描述                                                                     |
|---------|------------------------------------------------------------------------|
| `name`  | 文件或目录名称                                                                |
| `type`  | 对象类型：`file` 或 `directory`                                              |
| `size`  | 根据 [autoindex_exact_size](#autoindex-exact-size) 的对象大小；<br/>对于目录 — `0` |
| `mtime` | Unix 时间格式的最后修改时间                                                       |

HTML

```html
<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

```xml
<?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>
```

JSON

```json
[
{
    "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"
}
]
```

JSONP

```javascript
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"
}
]);
```

<a id="index-3"></a>

<a id="autoindex-localtime"></a>

### autoindex_localtime

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `autoindex_localtime` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `autoindex_localtime off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

对于 HTML [格式](#autoindex-format)，指定目录列表中的时间是以本地时区还是以 UTC 输出。
