官方文档:http://nginx.org/en/docs/http/ngx_http_autoindex_module.html
文件访问模板:ngx_http_autoindex_module
一、启用或禁用目录列表输出。
句法: autoindex on | off;
默认: autoindex off;
内容: http, server, location
二、输出文件大小千字节,兆字节和千兆字节。
句法: autoindex_exact_size on | off;
默认: autoindex_exact_size on;
内容: http,server,location
三、指定是否应在本地时区或UTC中输出目录列表中的时间
句法: autoindex_localtime on | off;
默认: autoindex_localtime off;
内容: http,server,location
四、设置目录列表的格式
句法: autoindex_format html | xml | json | jsonp;
默认: autoindex_format html;
内容: http,server,location
该指令出现在版本1.7.9中。
五、配置nginx文件
1)、创建一个目录并且复制文件到创建的目录下
mkdir -p /usr/share/nginx/html/autoindex && \
cp /etc/host* /usr/share/nginx/html/autoindex
2)、配置ngibx主配置文件
全部开启配置:
location /autoindex {
root /usr/share/nginx/html; #访问http://域名/autoindex 跳转到/usr/share/nginx/html/autoindex目录下
autoindex on; #默认开启文件
autoindex_exact_size on; #默认开启,默认字节为B
autoindex_localtime on; #默认关闭,现在开启同步时间为本地时区
}
3)访问测试:
#测试这里我放了个大文件存放到访问的目录下,进行测试
4)配置ngibx主配置文件
将字节与时间关闭
location /autoindex {
root /usr/share/nginx/html; #访问http://域名/autoindex 跳转到/usr/share/nginx/html/autoindex目录下
autoindex on; #默认开启文件
autoindex_exact_size off; #默认开启,默认字节为B
autoindex_localtime off; #默认关闭,现在开启同步时间为本地时区
}
5)检查、重启服务、访问测试:
nginx -t && nginx -s reload
6)综合个人选择搭配配置:
location /autoindex {
root /usr/share/nginx/html; #访问http://域名/autoindex 跳转到/usr/share/nginx/html/autoindex目录下
autoindex on; #默认开启文件
autoindex_format html; #默认为html格式
autoindex_exact_size off; #默认开启,默认字节为B
autoindex_localtime on; #默认关闭,现在开启同步时间为本地时区
访问测试:
格外补充设置目录列表的格式
1)、html格式:
2)、json格式:
3)、jsonp格式:
4)、xml格式:
补充: 个人后期上传中文的文件,出现乱码情况解析方式
修改配置
vim /etc/nginx/nginx.conf
charset utf-8;
重启nginx服务
nginx -s reload