首页 > 解决方案 > 在访问处理程序中创建的 nginx 变量在后续指令中使用时不包含值

问题描述

我为 nginx 编写了一个模块,它在 ACCESS 阶段注册。该模块解码并验证它接收到的令牌,并存储正在验证的用户的值(在令牌中编码),该值由我为变量定义的变量 get 函数提供。然而,在 location 块中变量的后续使用不会返回该值。在对该位置的下一个 HTTP 请求中,将返回上一个请求的值。它总是不同步 - 当前请求返回上一个 HTTP 请求的名称。

这是我的 nginx.conf 的相关部分:

           location /introspect {
                    set_form_input $token token;        # parse the request body

                    # decode the token, and if valid save user name
                    jwt_decode aud=$aud token=$token;   

                    # $jwt_user is defined by the module and returns the saved user name
                    set $whoami $jwt_user;              
                    try_files $uri @success;
            }
            location @success {
                    return 200 '{"active" : true, "user" : "$whoami"}';
            }

关于可能出现什么问题的任何想法?

标签: nginx

解决方案


推荐阅读