Nginx [SOLVED]: set_by_lua & os.getenv within openresty:alpine docker container

Nginx [SOLVED]: set_by_lua & os.getenv within openresty:alpine docker container

Home Forums Nginx Nginx [SOLVED]: set_by_lua & os.getenv within openresty:alpine docker container

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36707

    Anonymous

    QuestionQuestion

    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?

    #36708

    Anonymous

    Accepted AnswerAnswer

    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.

    Source: https://stackoverflow.com/questions/47969848/set-by-lua-os-getenv-within-openrestyalpine-docker-container
    Author: Tarun Lalwani
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.