Nginx学习笔记 autoindex on

100人浏览   2025-04-21 00:26:47

基本功能

用户请求以 / 结尾时,列出目录结构

指令集

autoindex
autoindex_exact_size
autoindex_format
autoindex_localtime

语法

语法:        autoindex on|off;
默认值:    autoindex off;
上下文:    http server location
解释:    是否开启此功能

autoindex_exact_size

语法:        autoindex_exact_size on|off;
默认值:    autoindex_exact_size on;
上下文:    http server location
解释:    是否在浏览器中显示文件大小,off为人性化显示

autoindex_format

语法:        autoindex_format html|xml|json|jsonp;
默认值:    autoindex_format html;
上下文:    http server location
解释:    目录结构的返回格式

autoindex_localtime

语法:        autoindex_localtime on|off;
默认值:    autoindex_localtime off;
上下文:    http server location
解释:    时间格式

配置段信息

# 资源路径 /opt/source/download/
# 注意不要出现index.html|htm
server {
    listen 80;
    server_name ~.*;
    
    location /# 资源路径 /opt/source/download/
# 注意不要出现index.html|htm
server {
    listen 80;
    server_name ~.*;
    
    location /download/ {
        root /opt/source;
       # index b.html;
        autoindex on;
        autoindex_exact_size off;
        autoindex_format html;
        autoindex_localtime off;
    }
}
    
/ {
        root /opt/source;
       # index b.html;
        autoindex on;
        autoindex_exact_size off;
        autoindex_format html;
        autoindex_localtime off;
    }
}

这样当访问 http://xxx.com/download/路径时 会展示/opt/source/ 下的文件列表

相关推荐