24

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?

1 Answer 1

27

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.

Sign up to request clarification or add additional context in comments.

7 Comments

@Jacobian, you may want to accept the answer if it worked for you.
Yes, sure! Thank you, sir!
"you'd need to specify env PATH; in nginx.conf". Can you please show example? Should I also specify a path? or just add "env PATH" ? Thanks.
Right; that's the entire command you need to add to nginx.conf.
@PaulKulchenko Hi, I had the same issue. I defined a new env var "export SECRET=mySecret" and inside nginx.conf I specify env SECRET; but when calling it, it seems like nothing exists. Only if I specify an env var that already existed, calling it will print back the right value. I opened a thread please take a look if you can: stackoverflow.com/questions/66518718/…
|

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.