Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

environment variables in config files #105

Open
1 task done
iridial opened this issue Dec 2, 2024 · 1 comment
Open
1 task done

environment variables in config files #105

iridial opened this issue Dec 2, 2024 · 1 comment

Comments

@iridial
Copy link

iridial commented Dec 2, 2024

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

Copy link

github-actions bot commented Dec 2, 2024

Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Issues
Development

No branches or pull requests

1 participant