P1-19:nginx服务器如何禁止访问目录(但是可以访问具体内容)

原配置

        location /repo {
            alias D:\Repo;
            # alias Z:;
            allow all;
            autoindex on;
            autoindex_exact_size off;
            autoindex_localtime on;
            # charset utf-8;#unicode,gbk,utf-8
            #跨域
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers X-Requested-With;
            add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
        }

修改后的配置

        location /repo {
            alias D:\Repo;
            # alias Z:;
            allow all;
            autoindex off;
            autoindex_exact_size off;
            autoindex_localtime on;
            # charset utf-8;#unicode,gbk,utf-8
            #跨域
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers X-Requested-With;
            add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
        }

将autoindex 的值从on 改为off,即不允许访问/repo目录,但是目录内的文件仍然可以访问到。

posted @ 2019-08-30 10:25  superisland  阅读(775)  评论(0)    收藏  举报