location ~ ^/cdn/(common|gamedetail)/.*.html$ {
rewrite_by_lua '
local args = ngx.req.get_uri_args()
local uri = ngx.var.uri
local rewrite_flag = args["rewrite_flag"] or 0
set_arr["match_flag"] = 1
if(rewrite_flag == "0") then
set_arr["rewrite_flag"] = 1
ngx.req.set_uri_args(set_arr)
ngx.req.set_uri(uri, true)
end
';
set_by_lua $match_flag '
local args = ngx.req.get_uri_args()
local match_flag = args["match_flag"] or 0
return match_flag;
';
//为什么rewrite_by_lua 执行重定向后,$match_flag不等于1呢
}
[debug] 23730#0: 315470 test location: ~ "^/cdn/(common|gamedetail)/..html$"
[debug] 23730#0: 315470 using configuration "^/cdn/(common|gamedetail)/..html$"
[debug] 23730#0: *315470 http cl:-1 max:52428800
[debug] 23730#0: *315470 rewrite phase: 3
[debug] 23730#0: *315470 rewrite phase: 4
[debug] 23730#0: *315470 add cleanup: 0000000001EBCA08
[debug] 23730#0: *315470 lua creating new vm state
[debug] 23730#0: *315470 lua initializing lua registry
[debug] 23730#0: *315470 lua initializing lua globals
[debug] 23730#0: *315470 lua initialize the global Lua VM 00007FD4FCA0B380
[debug] 23730#0: *315470 malloc: 0000000001D7BCC0:16
[debug] 23730#0: *315470 http cleanup add: 0000000001EBCA20
[debug] 23730#0: *315470 code cache lookup (key='set_by_lua_nhli_96f61900b22bbe42b629b4fdf2585e13', ref=1)
[debug] 23730#0: *315470 code cache miss (key='set_by_lua_nhli_96f61900b22bbe42b629b4fdf2585e13', ref=1)
[debug] 23730#0: *315470 http script value (post filter): "0"
[debug] 23730#0: *315470 http script set $match_flag
[debug] 23730#0: *315470 http script value: "0"
[debug] 23730#0: *315470 lua rewrite handler, uri:"/cdn/common/home-home-Recommend-1-2-jp-1.html" c:1
[debug] 23730#0: *315470 lua post read for rewrite/access phases
[debug] 23730#0: *315470 code cache lookup (key='nhlf_4e209f946a49788349149d0c4bfa6854', ref=2)
[debug] 23730#0: *315470 code cache miss (key='nhlf_4e209f946a49788349149d0c4bfa6854', ref=2)
[debug] 23730#0: *315470 lua creating new thread
[debug] 23730#0: *315470 lua reset ctx
[debug] 23730#0: *315470 http lua finalize threads
[debug] 23730#0: *315470 lua run thread, top:0 c:1
[debug] 23730#0: *315470 lua set uri jump to "/cdn/common/home-home-Recommend-1-2-jp-1.html"
[debug] 23730#0: *315470 lua resume returned 1
[debug] 23730#0: *315470 lua thread yielded
[debug] 23730#0: *315470 lua thread aborting request with URI rewrite jump: "/cdn/common/home-home-Recommend-1-2-jp-1.html?rewrite_flag=1&match_flag=1"
[debug] 23730#0: *315470 lua request cleanup: forcible=1
[debug] 23730#0: *315470 http lua finalize threads
[debug] 23730#0: *315470 lua deleting light thread 00007FD4FCA06558 (ref 1)
[debug] 23730#0: *315470 http lua unref thread 00007FD4FCA06558: 1
[debug] 23730#0: *315470 post rewrite phase: 6
[debug] 23730#0: *315470 uri changes: 11
[debug] 23730#0: 315470 test location: ~ "^/cdn/(common|gamedetail)/..html$"
[debug] 23730#0: 315470 using configuration "^/cdn/(common|gamedetail)/..html$"
[debug] 23730#0: *315470 http cl:-1 max:52428800
[debug] 23730#0: *315470 rewrite phase: 3
[debug] 23730#0: *315470 rewrite phase: 4
[debug] 23730#0: *315470 lua reset ctx
[debug] 23730#0: *315470 http lua finalize threads
[debug] 23730#0: *315470 http cleanup add: 0000000001EBCD48
[debug] 23730#0: *315470 code cache lookup (key='set_by_lua_nhli_96f61900b22bbe42b629b4fdf2585e13', ref=1)
[debug] 23730#0: *315470 code cache hit (key='set_by_lua_nhli_96f61900b22bbe42b629b4fdf2585e13', ref=1)
[debug] 23730#0: *315470 http script value (post filter): ""
[debug] 23730#0: *315470 http script set $match_flag
[debug] 23730#0: *315470 http script value: "0"