一、如果接口请求地址是 http://localhost/get/{id}
示例:
http://localhost/get/123
123
是变量id
的值
需要让nginx中的lua脚本获取到值的话,配置
nginx配置:
location /get {
set $id $1; #定义一个变量,变量名为 id,$1 为http://localhost/get/后面第一个参数
content_by_lua_file demo.lua; #使用lua脚本
}
demo.lua配置:
通过 ngx.var.变量名
就能获取到。
示例:
local id = ngx.var.id;
这样就能通过上面的id
变量拿到值为 123
。
二、如果接口请求地址是http://localhost/get?id=123
nginx配置:
location /get {
content_by_lua_file demo.lua; #使用lua脚本
}
demo.lua配置:
通过 ngx.var.arg_变量名;
就能获取到。
示例:
local id = ngx.var.arg_id;
这样就能通过上面的id
变量拿到值为 123
。