Reputation: 2171
I'm running openresty
nginx within official alpine-fat
docker image, and openresty process starts with nobody
user.
I need to set nginx variable with the next string:
set_by_lua $var 'return os.getenv("ENV_VAR")';
docker-compose.yml
contains the next block:
build:
context: .
dockerfile: ./Dockerfile.nginx
environment:
- ENV_VAR=value
But, nginx worker process seems not getting its value, and $var
remains empty.
I tried to add export ENV_VAR=value
to /etc/profile
file, but no use.
I tried to run openresty with nginx
user, but it also can't see the value of ENV_VAR
variable.
How can I make that thing work, if I can?
Upvotes: 1
Views: 4278
Reputation: 146610
Try adding env ENV_VAR;
to your nginx config. By default nginx will discard all environment variables, this will allow to save it.
From https://nginx.org/en/docs/ngx_core_module.html#env
Syntax: env variable[=value];
Default:
env TZ;
Context: main
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.
Upvotes: 5