3

I would like to assign the value to the nginx variable.
This is my sample code.

location / {
    set $TOKEN;
    content_by_lua_block {
        result = io.popen("echo 'https://google.com'") # or any command that will return value to result
        ngx.var.TOKEN = result:read()
    }
    proxy_pass ${TOKEN};

Do anyone have idea about it?

1 Answer 1

4

Use set_by_lua_block:

location / {
    set $proxy '';              
    set_by_lua_block $proxy {
        local result = io.popen("echo 'https://www.google.com'")
        return result:read()
    }
    proxy_pass $proxy;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.