|
= 表示精确匹配 ^~ 表示uri以某个字符串开头 ~ 正则匹配(区分大小写) ~* 正则匹配(不区分大小写) !~和!~*分别为区分大小写不匹配及不区分大小写不匹配的正则 / 任何请求都会匹配 匹配优先级: = > ^~ > / 举例: #对某些特定后缀名禁止访问 location ~* \.(txt|doc)$ { deny all; } #禁止用户访问http://www.xxxx.com/path/test.php location ^~ /test { deny all; } #禁止用户访问/config.ini location = /config.ini { return 404; } #禁止用户访问/config目录 location = /config/ { return 404; } #禁止访问目录(结尾/不能少) location ^~ /test/ { deny all; } #禁止访问目录下文件 location ^~ /test { deny all; } 禁止访问某些后缀文件 location ~ \.(ini|conf|txt)$ { deny all; }
|