Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set variable inoperative!! #1120

Closed
leehomewl opened this issue Feb 11, 2020 · 3 comments
Closed

set variable inoperative!! #1120

leehomewl opened this issue Feb 11, 2020 · 3 comments

Comments

@leehomewl
Copy link
Contributor

Hi:
我开发一个插件, 我在 bin/apisix 中加入初始化变量,我发现一个奇怪的问题:
如果 我设置这个变量为为空的时候
location / {
......
set $skip '';
......
}
我可以在插件 /lua/apisix/plugins目录下通过下面的rewrite阶段去修改这个变量, 并且后面的服务可以用到修改后的值。 是正常的

function _M.rewrite(conf, ctx)
ngx_var.skip = 0
end

但如果我改成下面的情况, 初始化这个值得时候设置为1 ,此时,我的插件就不其作用了,修改后的值似乎没有生效, 我测试了很多遍, 一直无法解决。 能帮忙确认下是什么原因吗?

location / {
......
set $skip 1 ;
......
}

@leehomewl
Copy link
Contributor Author

leehomewl commented Feb 11, 2020

我打算加入 srcache-nginx-module的模块进来, 我在openresty 上 用rewrite_by_lua 就非常正常。
但是我在 apisix 上使用的 插件的plugins 的rewrite 就无法成功, 每次赋值都好像执行阶段顺序没有对, 有遇到这种类似的情况的吼一下,谢谢

下面是openresty 正常的写法, 都是ok的。

location /test_foo {

 set $key $uri$args;
 srcache_fetch GET /memc $key;
 srcache_store PUT /memc $key;
 srcache_store_statuses 200 301 302;
set $fetch_skip '1';
set $store_skip '1';
rewrite_by_lua '
     ngx.var.fetch_skip = 0
     ngx.var.store_skip = 0
';
srcache_fetch_skip $fetch_skip;
srcache_store_skip $store_skip;
 proxy_pass  http://192.168.12.148:81;
}

}

@membphis
Copy link
Member

The apisix run both ".access" and ".rewrite" in the "access" phase.

https://github.com/apache/incubator-apisix/blob/master/bin/apisix#L334-L336

@leehomewl
Copy link
Contributor Author

The apisix run both ".access" and ".rewrite" in the "access" phase.

https://github.com/apache/incubator-apisix/blob/master/bin/apisix#L334-L336

好的,明白了, 我的修改是 set_by_lua 和 rewrite_by_lua 2个执行阶段的,所以在access就无效了。
谢谢哈。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants