How to reference OS Environment Variales in nginx.conf

agentzh agentzh at
Fri Sep 16 04:06:23 UTC 2011

On Fri, Sep 16, 2011 at 5:03 AM, caoxingk <nginx-forum at> 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
> 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:

    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:
(it'll be easier if you use the ngx_openresty bundle).


More information about the nginx mailing list