Skip to content

environment variables in config files #105

Closed as not planned
Closed as not planned
@iridial

Description

@iridial

Is this a new feature request?

  • I have searched the existing issues

Wanted change

hello, would it be possible to use values set in environment variables inside nginx config? the official nginx container allows this by using templates: https://github.com/nginxinc/docker-nginx/blob/master/entrypoint/20-envsubst-on-templates.sh

for reference, this solution uses such feature:
https://serverfault.com/questions/577370/how-can-i-use-environment-variables-in-nginx-conf

docker-compose.yml:

version: "3.9"
services:
  nginx:
    image: nginx:1.23
    volumes:
        - ./template-variables:/etc/nginx/templates/10-variables.conf.template:ro

    environment:
        EXTERNAL_IP: "1.2.3.4"

template-variables:

map $host $external_ip {
  default "$EXTERNAL_IP";
}

nginx.conf:

server {
     location / {

          proxy_set_header X-Real-IP $external_ip;
      }
}

Reason for change

for instance, in a reverse proxy setup, if I need to set a secret which needs be passed in a request to the backend,
I'd like to set its value in the container env variables, instead of writing it in the nginx config directly.

proxy_set_header X-Api-Key $mysecret;

Proposed code change

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions