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

Accessing testcookie_ok variable from log_by_lua_block #67

Open
tokumeo opened this issue Dec 19, 2018 · 6 comments
Open

Accessing testcookie_ok variable from log_by_lua_block #67

tokumeo opened this issue Dec 19, 2018 · 6 comments

Comments

@tokumeo
Copy link

tokumeo commented Dec 19, 2018

I have a use case for setting another variable depending on the value of testcookie_ok variable. I'm trying to achieve this with lua-nginx-module by using log_by_lua_block directive. Unfortunately, when reading testcookie_ok from lua using ngx.var API from log_by_lua_block, the value of testcookie_ok is always nil. But when adding testcookie_ok to access log, the value is either "0" or "1" depending on the results of the validation. Could you please provide some insight on why testcookie_ok might be nil when reading it from log_by_lua_block?

   testcookie_name YouShallNotPass;
   testcookie_session $remote_addr;
   testcookie on;

    log_by_lua_block {
        ngx.log(ngx.DEBUG, "testcookie_ok=", ngx.var.testcookie_ok)
    }

Here are the logs:

# no cookie
2018/12/19 14:17:13 [debug] 19639#19639: *19409 [lua] log_by_lua(default.conf:33):3: testcookie_ok=nil
192.168.122.1 - - [19/Dec/2018:14:17:13 +0300] "GET / HTTP/1.1" 307 171 "-" "curl/7.47.0" "-" testcookie_ok=0

# correct cookie
2018/12/19 14:17:53 [debug] 19639#19639: *19490 [lua] log_by_lua(default.conf:33):3: testcookie_ok=nil
192.168.122.1 - - [19/Dec/2018:14:17:53 +0300] "GET / HTTP/1.1" 200 0 "-" "curl/7.47.0" "-" testcookie_ok=1

I've tried compiling nginx with different order of testcookie and lua-nginx modules, but the situation doesn't change.

@kyprizel
Copy link
Owner

Have you tried to change modules ordering during nginx compilation?

@tokumeo
Copy link
Author

tokumeo commented Dec 19, 2018

Yes, I tried both --add-module=testcookie-nginx-module --add-module=lua-nginx-module and --add-module=lua-nginx-module --add-module=testcookie-nginx-module

@hroost
Copy link

hroost commented Dec 19, 2018

@tokumeo have you tried to use pre-built packages of nginx with Lua from openresty.org?

@tokumeo
Copy link
Author

tokumeo commented Dec 19, 2018

@tokumeo have you tried to use pre-built packages of nginx with Lua from openresty.org?

No, I haven't tried that

@tokumeo
Copy link
Author

tokumeo commented Dec 19, 2018

I've managed to work around this problem using map directive for now, but I'm still curious why I can't get testcookie_ok variable using log_by_lua_block

@Mecanik
Copy link

Mecanik commented Jan 11, 2019

@tokumeo Can you share example?

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

4 participants