我正在official openresty
docker镜像中运行alpine-fat
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 worker进程似乎没有获得其值(value),并且
$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.
关于docker - openresty:alpine docker容器中的set_by_lua和os.getenv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47969848/