set_by_lua & os.getenv 在 openresty:alpine docker 容器内
set_by_lua & os.getenv within openresty:alpine docker container
我在 official alpine-fat
docker 映像中 运行ning openresty
nginx,并且 openresty 进程以 nobody
用户启动。
我需要使用下一个字符串设置 nginx 变量:
set_by_lua $var 'return os.getenv("ENV_VAR")';
docker-compose.yml
包含下一个块:
build:
context: .
dockerfile: ./Dockerfile.nginx
environment:
- ENV_VAR=value
但是,nginx 工作进程似乎没有得到它的值,$var
仍然是空的。
我试图将 export ENV_VAR=value
添加到 /etc/profile
文件,但没有用。
我尝试用 nginx
用户 运行 openresty,但它也看不到 ENV_VAR
变量的值。
如果可以的话,我怎样才能让它发挥作用?
尝试将 env ENV_VAR;
添加到您的 nginx 配置中。默认情况下 nginx 将丢弃所有环境变量,这将允许保存它。
来自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.
我在 official alpine-fat
docker 映像中 运行ning openresty
nginx,并且 openresty 进程以 nobody
用户启动。
我需要使用下一个字符串设置 nginx 变量:
set_by_lua $var 'return os.getenv("ENV_VAR")';
docker-compose.yml
包含下一个块:
build:
context: .
dockerfile: ./Dockerfile.nginx
environment:
- ENV_VAR=value
但是,nginx 工作进程似乎没有得到它的值,$var
仍然是空的。
我试图将 export ENV_VAR=value
添加到 /etc/profile
文件,但没有用。
我尝试用 nginx
用户 运行 openresty,但它也看不到 ENV_VAR
变量的值。
如果可以的话,我怎样才能让它发挥作用?
尝试将 env ENV_VAR;
添加到您的 nginx 配置中。默认情况下 nginx 将丢弃所有环境变量,这将允许保存它。
来自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.