How to reference OS Environment Variales in nginx.conf

Hi there,

After set a variable by set $name value, i can reference it like
$name,
but when i export a OS Environment Variale by env name_from_env, like
Core functionality said,
and i am sure the name_from_env is valid which defined form nginx’s
parent process.

But, my friends, how to reference it ?
$name_from_env or ${name_from_env} or %name_from_env% didn’t work what
i’ve tried before.

Thanks a lot.

Posted at Nginx Forum:

2ed version is here:

Posted at Nginx Forum:

On Fri, Sep 16, 2011 at 5:03 AM, caoxingk [email protected] wrote:

After set a variable by set $name value, i can reference it like
$name,
but when i export a OS Environment Variale by env name_from_env, like
Core functionality said,
and i am sure the name_from_env is valid which defined form nginx’s
parent process.

But, my friends, how to reference it ?

You can read system environment variables with ngx_lua enabled in your
nginx build: Lua | NGINX

env PATH;
http {
    ...
    server {
        location /path {
            set_by_lua $path 'return os.getenv("PATH")';
            ...
        }
    }

BTW, to use the set_by_lua directive, you also need to enable the
ngx_devel_kit module here: GitHub - vision5/ngx_devel_kit: Nginx Development Kit - an Nginx module that adds additional generic tools that module developers can use in their own modules
(it’ll be easier if you use the ngx_openresty bundle).

Regards,
-agentzh