原配置
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目录,但是目录内的文件仍然可以访问到。
P1-19:nginx服务器如何禁止访问目录(但是可以访问具体内容)
原文:https://www.cnblogs.com/superisland/p/11433539.html