编程技术分享平台

网站首页 > 技术教程 正文

Nginx学习笔记(12) autoindex(nginx use)

xnh888 2024-10-14 19:41:20 技术教程 13 ℃ 0 评论

基本功能

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

指令集

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/ 下的文件列表

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表