nginx使用的是模块ngx_http_autoindex_module来实现的,该模块处理以斜杠(“/“)结尾的请求,并生成目录列表。
nginx编译的时候会自动加载该模块,但是该模块默认是关闭的,使用下来指令来完成对应的配置
autoindex
启用或禁用目录列表输出
| 语法 | autoindex on|off; |
|---|---|
| 默认值 | autoindex off; |
| 位置 | http、server、location |
autoindex_exact_size
对应HTLM格式,指定是否在目录列表展示文件的详细大小
默认为on,显示出文件的确切大小,单位是bytes。改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
| 语法 | autoindex_exact_size on|off; |
|---|---|
| 默认值 | autoindex_exact_size on; |
| 位置 | http、server、location |
autoindex_format
设置目录列表的格式
| 语法 | autoindex_format html|xml|json|jsonp; |
|---|---|
| 默认值 | autoindex_format html; |
| 位置 | http、server、location |
autoindex_localtime
对应HTML格式,是否在目录列表上显示时间。
默认为off,显示的文件时间为GMT时间。改为on后,显示的文件时间为文件的服务器时间
案例
- 环境文件路径/home/download

Nginx配置
server {listen 8068;server_name localhost;location /download{root /home;autoindex on;autoindex_exact_size on;autoindex_format html;autoindex_localtime on;}}
访问效果

- xml格式

- json格式

