admin 发表于 2020-2-2 17:35:15

nginx location 匹配语法规则

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

页: [1]
查看完整版本: nginx location 匹配语法规则