简体   繁体   中英

How to access a variable value set inside Lua block in proxy pass

I am new to nginx. I have a variable set $myuser and updating the value ngx.var.myuser inside rewrite_by_lua. I want to pass this as a header in proxy_pass. I am using proxy_add_header to add $myuser but I am not getting the updated value.

code block:

location /
{

 set $myuser '';

    rewrite_by_lua_block
    {
        local user=//code to get the updated value
       //perform some redirection logic on error
        ngx.var.myuser= user
       
       
    }
  
proxy_pass  "https://backend.com"
proxy_set_header  myheader  $myuser


}

value of $myuser is coming as empty but it's getting retrieved fine inside the lua block.

Below code worked. No need to set variable anduse it in proxy_set_header. We can set the header inside the lua block

rewrite_by_lua_block
    {
        local user=//code to get the updated value
       //perform some redirection logic on error
       
         ngx.req.set_header("myheader", user)
       
       
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM