Open Nginx autoindex function

开启 Nginx 自动文件目录

在 nginx.conf 中加入以下代码即可

location /YOUR_PATH/ {
autoindex on; #开启文件目录
autoindex_exact_size off; #防止以字节数显示文件大小
autoindex_localtime on;
autoindex_format html;
charset utf-8,gbk; #避免中文乱码


The ngx_http_autoindex_module module processes requests ending with the slash character (‘/’) and produces a directory listing. Usually a request is passed to the ngx_http_autoindex_module module when the ngx_http_index_module module cannot find an index file.

Example Configuration

location / {
autoindex on;


Syntax: autoindex on | off;
autoindex off;
Context:    http, server, location

Enables or disables the directory listing output.

Syntax: autoindex_exact_size on | off;
autoindex_exact_size on;
Context:    http, server, location

For the HTML format, specifies whether exact file sizes should be output in the directory listing, or rather rounded to kilobytes, megabytes, and gigabytes.

Syntax: autoindex_format html | xml | json | jsonp;
autoindex_format html;
Context:    http, server, location
This directive appeared in version 1.7.9.

Sets the format of a directory listing.

When the JSONP format is used, the name of a callback function is set with the callback request argument. If the argument is missing or has an empty value, then the JSON format is used.

The XML output can be transformed using the ngx_http_xslt_module module.

Syntax: autoindex_localtime on | off;
autoindex_localtime off;

Context: http, server, location
For the HTML format, specifies whether times in the directory listing should be output in the local time zone or UTC.

0 0 vote
Article Rating