lua-resty-location-match
确定请求进入的 location
$ opm get firesnow/lua-resty-location-match
lua-resty-location-match
确定请求进入的 location
概述
http {
init_by_lua_block{
lm = require "resty.location.match"
location_list = {
"/",
"= /test1",
"~ /test2",
"~* /test3",
"^~ /test4",
"/test5",
}
}
server {
listen 80;
location / {
content_by_lua_block {
ngx.say('/')
ngx.say(lm:match_location(ngx.var.uri, location_list));
}
}
location = /test1 {
content_by_lua_block {
ngx.say('= /test1')
ngx.say(lm:match_location(ngx.var.uri, location_list));
}
}
location ~* /test3 {
content_by_lua_block {
ngx.say('~* /test3')
ngx.say(lm:match_location(ngx.var.uri, location_list));
}
}
location ^~ /test4 {
content_by_lua_block {
ngx.say('^~ /test4')
ngx.say(lm:match_location(ngx.var.uri, location_list));
}
}
location /test5 {
content_by_lua_block {
ngx.say('/test5')
ngx.say(lm:match_location(ngx.var.uri, location_list));
}
}
}
}
方法
match_location
`语法: match_location = match_location(uri,location_list)
`
从 location 列表中获取匹配 location,如同 Nginx 规则。
注意: 确保 location_list
的顺序与 Nginx 配置文件中 location 的顺序一致。
版权和许可
该模块采用 BSD 许可证授权。
版权所有 (c) 2016-2017,firesnow zhangce5413@gmail.com
保留所有权利。
允许在符合以下条件的情况下,以源代码或二进制形式,修改或未修改地重新分发本软件。
源代码的重新分发必须保留上述版权声明、本条件列表以及以下免责声明。
二进制形式的重新分发必须在随发行提供的文档和/或其他材料中复制上述版权声明、本条件列表以及以下免责声明。
本软件由版权持有人和贡献者“按原样”提供,任何明示或暗示的担保,包括但不限于适销性和特定目的适用性的暗示担保,均被排除在外。在任何情况下,版权持有人或贡献者均不对任何直接、间接、附带、特殊、示例性或后果性损害(包括但不限于替代商品或服务的采购;使用、数据或利润损失;或业务中断)负责,无论这些损害是由于本软件的使用或其他原因造成的,无论是在合同、严格责任或侵权行为(包括疏忽或其他原因)的法律理论下,即使已被告知此类损害的可能性。
作者
firesnow
许可证
2bsd
版本
-
确定请求进入的 location 2016-12-21 16:03:36
-
确定请求进入的 location 2016-12-21 14:38:14
-
确定请求进入的 location 2016-12-20 06:21:38
-
确定请求进入的 location 2016-12-20 06:18:46
-
确定请求进入的 location 2016-11-27 15:44:28
-
确定请求进入的 location 2016-11-27 15:19:02