nginx-proxy icon indicating copy to clipboard operation
nginx-proxy copied to clipboard

Config using environment variables

Open poma opened this issue 6 years ago • 3 comments

Currently the only way to set a global or per-vhost config is to mount a corresponding conf file into nginx container. Even though it can be done via creating custom container or mounting a volume with config files, using env vars would be more easy and effortless. My proposition is as follows:

At startup, scan all env vars starting with NGINX_* and add corresponding entries to /etc/nginx/conf.d/environment.conf and for each vhost do the same for hosts env vars. This way we would avoid hardcoding and maintaining an array of possible env variable names. Example usage from docker-compose:

services:
  nginx:
    image: jwilder/nginx-proxy
    environment:
      NGINX_CLIENT_MAX_BODY_SIZE: 30M
    ports:
      - 80:80
    ...
  app:
    image: app
    environment:
      VIRTUAL_HOST: example.com
      NGINX_ACCESS_LOG: 'off'

or from the command line:

 docker run -d -p 80:80 -e NGINX_CLIENT_MAX_BODY_SIZE=30M ... jwilder/nginx-proxy

There are 2 related issues #597 and #688 but they are a few years old and unanswered.

Is there interest for implementing this? I can try to do it. Maybe a similar solution already exists?

Or is it a bad idea? If so, why?

poma avatar Sep 04 '19 20:09 poma

I've made a simple wrapper that adds env variables to global config using a shell script https://github.com/poma/docker-gen

poma avatar Sep 05 '19 04:09 poma

Need this

drequivalent avatar Sep 16 '21 23:09 drequivalent

Any update?

jonaaix avatar May 03 '23 10:05 jonaaix