【发布时间】:2017-09-28 01:24:06
【问题描述】:
当在 Nginx 中从 server_name 创建一个变量并使用 ngx.location.capture 调用不同的端点时,该变量就消失了。
下面的例子通过调用 testlocalhost 和 acclocalhost 来演示:
server {
listen 1003;
server_name ~^(?<name>test|acc)localhost$; #<-Name is set here
location / {
#return 200 $name; #This would return the expected test or acc
content_by_lua 'local options = {
method = ngx.HTTP_GET,
}
local res = ngx.location.capture("/internal", options)
ngx.say(res.body)';
}
location /internal {
return 200 $name; #<- Name is empty here
}
}
有什么方法可以在不修改body或者使用url参数的情况下维护端点之间的变量?
【问题讨论】: