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

Already on GitHub? Sign in to your account

var can't be modify in access_by_lua #189

Closed
edwardpro opened this Issue Dec 14, 2012 · 2 comments

Comments

Projects
None yet
2 participants
        set $abc 'sdfs';
        access_by_lua '
            ngx.var.abc = "abc"
        ';
        set_by_lua $xxx '  ngx.log(ngx.ERR,ngx.var.abc) ';

log:

print as 'sdfs' not "abc"

Owner

agentzh commented Dec 14, 2012

Hello!

On Fri, Dec 14, 2012 at 1:14 AM, edwardpro notifications@github.com wrote:

    set $abc 'sdfs';
    access_by_lua '
        ngx.var.abc = "abc"
    ';
    set_by_lua $xxx '  ngx.log(ngx.ERR,ngx.var.abc) ';

log:

print as 'sdfs' not "abc"

Because the actual running order of your directives is actually like this:

set $abc 'sdfs';
set_by_lua $xxx '  ngx.log(ngx.ERR,ngx.var.abc) ';
access_by_lua 'ngx.var.abc = "abc"'

because set and set_by_lua both run in the nginx "rewrite" request
processing phase, before the "access" phase at which access_by_lua is
run. No matter how you write them in the nginx.conf. So the output in
error.log looks correct.

Please read my Nginx tutorials on more details on nginx directive
running order to prevent such basic mistakes :)

http://agentzh.org/misc/nginx/agentzh-nginx-tutorials-enuk.html

Best regards,
-agentzh

Owner

agentzh commented Jan 21, 2013

Consider it resolved.

@agentzh agentzh closed this Jan 21, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment