命令 | 默认值 | 值域 | 作用域 | EG |
---|---|---|---|---|
autoindex | off | on:开启目录浏览;off:关闭目录浏览 | http, server, location | autoindex on;打开目录浏览功能 |
autoindex_format | html | html、xml、json、jsonp 分别用这几个风格展示目录 | http, server, location | autoindex_format html; 以网页的风格展示目录内容。该属性在1.7.9及以上适用 |
autoindex_exact_size | on | on:展示文件字节数;off:以可读的方式显示文件大小 | http, server, location | autoindex_exact_size off; 以可读的方式显示文件大小,单位为 KB、MB 或者 GB,autoindex_format为html时有效 |
autoindex_localtime | off | on、off:是否以服务器的文件时间作为显示的时间 | http, server, location | autoindex_localtime on; 以服务器的文件时间作为显示的时间,autoindex_format为html时有效 |
完整配置如下:
location /download
{
root /home/map/www/; #指定目录所在路径
autoindex on; #开启目录浏览
autoindex_format html; #以html风格将目录展示在浏览器中
autoindex_exact_size off; #切换为 off 后,以可读的方式显示文件大小,单位为 KB、MB 或者 GB
autoindex_localtime on; #以服务器的文件时间作为显示的时间
charset utf-8,gbk; #展示中文文件名
}
目录浏览美化
要查看Nginx编译了哪些模块,执行以下命令:
2>&1 nginx -V | tr ' ' '\n'|grep module
查看完整的编译参数:nginx -V
动态编译添加Nginx模块
- 在GitHub下载最新源码:ngx-fancyindex
- Nginx-Index源码下载下来后,解压,放到nginx源码目录(/usr/local/nginx)中,执行下面的代码,编译:
nginx -V
参数添加--add-module=ngx-fancyindex-0.4.2
make
这里不要 make install!!- 选择Fancy Index主题 Nginx-Fancyindex-Theme
Fancy Index 配置
- 进入Nginx安装的web目录,执行nginx -V,输出configure arguments: --prefix=/usr/local/nginx,就是这个目录
- git clone https://github.com/lanffy/Nginx-Fancyindex-Theme.git
- 在nginx location模块中添加Fancy Index配置,如下:
location /download
{
include /usr/local/nginx/html/Nginx-Fancyindex-Theme/fancyindex.conf; # 目录美化配置
root /home/map/www/; #指定目录所在路径
autoindex on; #开启目录浏览
autoindex_format html; #以html风格将目录展示在浏览器中
autoindex_exact_size off; #切换为 off 后,以可读的方式显示文件大小,单位为 KB、MB 或者 GB
autoindex_localtime on; #以服务器的文件时间作为显示的时间
charset utf-8,gbk; #展示中文文件名
}
#fancyindex.conf
fancyindex on;
fancyindex_localtime on;
fancyindex_exact_size off;
fancyindex_header "/Nginx-Fancyindex-Theme/header.html";
fancyindex_footer "/Nginx-Fancyindex-Theme/footer.html";
# Ignored files will not show up in the directory listing, but will still be public.
fancyindex_ignore "examplefile.html";
# Making sure folder where files are don't show up in the listing.
fancyindex_ignore "Nginx-Fancyindex-Theme";
# Maximum file name length in bytes, change as you like.
fancyindex_name_length 255;