醉丶春风的Blog

千里之行, 始于足下



nginx目录列表和目录访问权限设置


1.目录列表(directory listing)

nginx让目录中的文件以列表的形式展现只需要一条指令

autoindex on;

autoindex可以放在location中,只对当前location的目录起作用。你也可以将它放在server指令块则对整个站点都起作用。或者放到http指令块,则对所有站点都生效。

下面是一个简单的例子:

server {
        listen   80;
        server_name  domain.com www.domain.com;
        access_log  /var/...........................;
        root   /path/to/root;
        location / {
                index  index.php index.html index.htm;
        }
        location /somedir {
               autoindex on;
        }
}

2.nginx禁止访问某个目录

跟Apache的Deny from all类似,nginx有deny all指令来实现。

禁止对叫dirdeny目录的访问并返回403 Forbidden,可以使用下面的配置:

location /dirdeny {
      deny all;
      return 403;
}

文章来源:http://www.nginx.cn/692.html


作者: 徐善通
地址: https://www.xstnet.com/article-73.html
声明: 除非本文有注明出处,否则转载请注明本文地址


我有话说



最新回复


正在加载中....

Copyrights © 2016-2019 醉丶春风 , All rights reserved. 皖ICP备15015582号-1