nginx location rewrite 禁止访问某个目录

Location 指令,是用来为匹配的 URI 进行配置

http://www.baidu.com/test/index.php?a=1&b=ture 这里面/test/index.php就是nginx里的uri,就是变量$uri

location [=|~|~*|^~|@] /uri/ { … }

〖=〗 表示精确匹配,如果找到,立即停止搜索并立即处理此请求。

〖~ 〗 表示区分大小写匹配

〖~*〗 表示不区分大小写匹配

〖^~ 〗 表示只匹配字符串,不查询正则表达式。

〖@〗 指定一个命名的location,一般只用于内部重定向请求。

location  = / {
  # 只匹配对 / 目录的查询.
  [ config A ]
}
location  / {
  # 匹配以 / 开始的查询,即所有查询都匹配。
  [ config B ]
}
location ^~ /images/ {
  # 匹配以 /images/ 开始的查询,不再检查正则表达式。
  [ config C ]
}
location ~* \.(gif|jpg|jpeg)$ {
  # 匹配以gif, jpg, or jpeg结尾的文件,但优先级低于config C。
  [ config D ]
}

location ~ .*\.(bak|sql)?$

{

rewrite "^.*$" /; //.bak .sql文件的访问结果是主页

}

location ^~ /include/

{

rewrite "^.*$" /; //include下的访问结果是主页

}