Unable to use environment variables in Lua code

13,977

You need to tell nginx to make environment variables available. From the docs for the env directive: "By default, nginx removes all environment variables inherited from its parent process except the TZ variable. This directive allows preserving some of the inherited variables, changing their values, or creating new environment variables."

So, in your case you'd need to specify env PATH; in nginx.conf.

Share:
13,977
Jacobian
Author by

Jacobian

Updated on June 08, 2022

Comments

  • Jacobian
    Jacobian almost 2 years

    I have some Lua code, which I use in my openresty nginx.conf file. This Lua code contains such lines:

    ...
    local secret = os.getenv("PATH")
    assert(secret ~= nil, "Environment variable PATH not set")
    ...
    

    Just for testing reasons I tried to check if PATH variable is set and for some reason the assert statement does not pass. I see in the console:

    Environment variable PATH not set

    However, when I run this

    $ echo $PATH
    

    I see, that this variable indeed has some value. So, what is wrong with that and how can I fix it?