在Nginx浏览器中打开目录浏览功能

 更新时间:2016年1月27日 20:14  点击:1456

在nginx中不像apache默认是打开目录浏览功能的,在nignx中目录浏览功能默认是关闭了,下面我来介绍在nginx中实现目录浏览功能的配置方法。

打开nginx.conf文件,在location server 或 http段中加入

autoindex on;

另外两个参数最好也加上去:
 

autoindex_exact_size off;

默认为on,显示出文件的确切大小,单位是bytes。
改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
 

autoindex_localtime on;

默认为off,显示的文件时间为GMT时间。
改为on后,显示的文件时间为文件的服务器时间
 

location /{
root  /var/www/html;
autoindex on;
} 

这段代码的意思就是把 /var/www/html目录作为根目录来直接列出来。


如果我们想只显示一个网站或一个目录,其实很简单,把该网站的.conf文件全部修改才行。如修改成如下即可:

server {
listen 80;
charset utf-8;
server_name localhost;
root /www/web/default;

location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}

[!--infotagslink--]

相关文章