Nginx-proxy: Nginx configuration by environment variables

Created on 23 Jan 2017  Â·  4Comments  Â·  Source: nginx-proxy/nginx-proxy

Currently if we want to add or override some config files we need to build our own image (usually Dockerfile with 2 lines).

How about to add possibility to insert configuration by env variables?

Example docker-compose.yml:

environment:
  CONFIG_GLOBAL: "client_max_body_size 50M;"
  CONFIG_WWW_EXAMPLE_COM: "client_body_buffer_size 10m;"
  CONFIG_GLOBAL_LOCATION: "client_max_body_size 50M;"
  CONFIG_WWW_EXAMPLE_COM_LOCATION: |
    client_body_buffer_size 10m;
    client_max_body_size 50M;

This variables will be printed in the right place by template.

Is PR welcome?

This feature will probably decrease need for adding other single-use-case features.

Most helpful comment

I use docker-compose, and it would be more convenient for me to specify my SSL certificates’ content in environment variables, for example (shortened for brevity):

version: '3'

services:
  proxy:
    image: jwilder/nginx-proxy
    environment:
      SSL_CERTIFICATE: |
        -----BEGIN CERTIFICATE-----
        MIIEWzCCA0OgAwIBAgIJALMB1GItlJExMA0GCSqGSIb3DQEBCwUAMIGDMQswCQYD
        FWVwJcX8zm/b7bXNJdwX
        -----END CERTIFICATE-----
      SSL_CERTIFICATE_KEY: |
        -----BEGIN RSA PRIVATE KEY-----
        MIIEpQIBAAKCAQEArD22Jw/CWyyzxFnUnCsWtKN/jg2BVht6Eo5703og45LrJ5gB
        /JbxCUFWf8X3X7JPOn+Hlz/VvOXKy0gxhSAtb9vd+5z0RGeZ8IL9+2o=
        -----END RSA PRIVATE KEY-----
      SSL_DHPARAM: |
        -----BEGIN DH PARAMETERS-----
        MIIBCAKCAQEAsSKY3K9w6VmRv4Mn7AAXK/U6S6DbBflqUNmEBsVkRUhSU15GVayj
        wOI8ijB2iWUCkh8uPklI8Z9NgQxetVS36wIBAg==
        -----END DH PARAMETERS-----

When nginx-proxy starts up, if these environment variables are set it would save them into files:

[ -n "${SSL_CERTIFICATE+1}" ]     && echo "$SSL_CERTIFICATE"     >> /etc/nginx/certs/ssl.crt
[ -n "${SSL_CERTIFICATE_KEY+1}" ] && echo "$SSL_CERTIFICATE_KEY" >> /etc/nginx/certs/ssl.key
[ -n "${SSL_DHPARAM+1}" ]         && echo "$SSL_DHPARAM"         >> /etc/nginx/certs/dhparam.pem

All 4 comments

I would like that. what I need is to set ssl_prefer_server_ciphers off;, I'm currently thinking about a fork. Or is there a better way?

The way to achieve this is with docker volumes as documented in the README file

Docker volumes are not useable if you want to use remote ephemeral hosts.
On the other hand, env variables or labels are super handy with Docker
Compose.

Jan Pobořil

2017-02-03 13:52 GMT+01:00 Thomas LÉVEIL notifications@github.com:

The way to achieve this is with docker volumes as documented in the README
file
https://github.com/jwilder/nginx-proxy/blob/master/README.md#custom-nginx-configuration

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/jwilder/nginx-proxy/issues/688#issuecomment-277239888,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAlfWEN6kdGYhd9ZRA4KYm4orh42oYPRks5rYyL3gaJpZM4Lrj7k
.

I use docker-compose, and it would be more convenient for me to specify my SSL certificates’ content in environment variables, for example (shortened for brevity):

version: '3'

services:
  proxy:
    image: jwilder/nginx-proxy
    environment:
      SSL_CERTIFICATE: |
        -----BEGIN CERTIFICATE-----
        MIIEWzCCA0OgAwIBAgIJALMB1GItlJExMA0GCSqGSIb3DQEBCwUAMIGDMQswCQYD
        FWVwJcX8zm/b7bXNJdwX
        -----END CERTIFICATE-----
      SSL_CERTIFICATE_KEY: |
        -----BEGIN RSA PRIVATE KEY-----
        MIIEpQIBAAKCAQEArD22Jw/CWyyzxFnUnCsWtKN/jg2BVht6Eo5703og45LrJ5gB
        /JbxCUFWf8X3X7JPOn+Hlz/VvOXKy0gxhSAtb9vd+5z0RGeZ8IL9+2o=
        -----END RSA PRIVATE KEY-----
      SSL_DHPARAM: |
        -----BEGIN DH PARAMETERS-----
        MIIBCAKCAQEAsSKY3K9w6VmRv4Mn7AAXK/U6S6DbBflqUNmEBsVkRUhSU15GVayj
        wOI8ijB2iWUCkh8uPklI8Z9NgQxetVS36wIBAg==
        -----END DH PARAMETERS-----

When nginx-proxy starts up, if these environment variables are set it would save them into files:

[ -n "${SSL_CERTIFICATE+1}" ]     && echo "$SSL_CERTIFICATE"     >> /etc/nginx/certs/ssl.crt
[ -n "${SSL_CERTIFICATE_KEY+1}" ] && echo "$SSL_CERTIFICATE_KEY" >> /etc/nginx/certs/ssl.key
[ -n "${SSL_DHPARAM+1}" ]         && echo "$SSL_DHPARAM"         >> /etc/nginx/certs/dhparam.pem
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jas2Ma picture Jas2Ma  Â·  4Comments

renfyld picture renfyld  Â·  3Comments

etiennemtl picture etiennemtl  Â·  3Comments

xixiaofinland picture xixiaofinland  Â·  3Comments

peperunas picture peperunas  Â·  4Comments