nginx设置列出文件或目录功能

在nginx的配置文件的http段或server段添加:

autoindex on;//自动显示目录
autoindex_exact_size off;//人性化方式显示文件大小否则以byte显示
autoindex_localtime on;//按服务器时间显示,否则以gmt时间显示 

查看效果

只开启单独目录

示例:只开启dir目录的文件列出功能

 location ~ /dir {
 autoindex on;
 autoindex_exact_size off;
 autoindex_localtime on
 charset utf-8,gbk; #防止中文乱码
                  }
server {
    listen       80;
    server_name  mirrors.cnbugs.com;
       root /data/;
    index index.html;

    location  /ubuntu/ {
       alias /data/ubuntu/;
       autoindex on;
       autoindex_exact_size off;
       autoindex_localtime on;
 }
}

发表评论

后才能评论