Sign inSign up

sshipway/nginx

By sshipway

•Updated over 10 years ago

Copy of nginx container, that allows passing of nginx.conf as an Env Var

Image
0

244

sshipway/nginx repository overview

This is an exact copy of the nginx container, but allows some additional environmental parameters.

NGINX_CONFIG : If this is set, then its contents are used to create the initial nginx.conf

NGINX_CERT_FILE, NGINX_KEY_FILE, NGINX_DOMAIN : If all of these are set, and NGINX_CERT_FILE does not exist, then a new key and certificate are generated with NGINX_DOMAIN as the CN. The certificate is self-signed with a 1 year validity, and 2048 bit key.

Example:

ssl-proxy:
  image: sshipway/nginx:1.9.9
  tty: true
  stdin_open: true
  ports:
    - 443:443/tcp
  links:
    - webserver:webserver
  environment:
    NGINX_CONFIG: >
      server {\n
        listen 443 ssl;\n
        ssl_certificate     certs/registry.crt;\n
        ssl_certificate_key certs/registry.key;\n
        location / {\n
          proxy_set_header Host $host;\n
          proxy_set_header X-Forwarded-Proto $scheme;\n
          proxy_set_header X-Forwarded-Host $http_host;\n
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n
          proxy_pass http://webserver:80/;\n
          proxy_http_version 1.1;\n
          proxy_set_header Upgrade $http_upgrade;\n
          proxy_set_header Connection "upgrade";\n
          proxy_read_timeout 900s;\n
        }\n
      }\n
    NGINX_CERT_FILE: /etc/nginx/certs/server.crt
    NGINX_KEY_FILE: /etc/nginx/certs/server.key
    NGINX_DOMAIN: www.example.com

Dockerfile:

FROM debian:jessie
MAINTAINER NGINX Docker Maintainers "[email protected]"

RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
RUN echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list

ENV NGINX_VERSION 1.9.9-1~jessie

RUN apt-get update && \
    apt-get install -y ca-certificates nginx=${NGINX_VERSION} && \
    rm -rf /var/lib/apt/lists/*

# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log
VOLUME ["/var/cache/nginx"]
EXPOSE 80 443 8443 8000

ADD startup.sh /usr/local/bin/startup.sh
CMD ["sh","-c","/usr/local/bin/startup.sh"]

startup.sh

if [ "$NGINX_CONFIG" != "" ];then
   echo Using passed configuration file
   echo "$NGINX_CONFIG" | sed 's/\\n/\n/g' > /etc/nginx/conf.d/nginx.conf
fi
if [ "$NGINX_CERT" != "" -a "$NGINX_CERT_FILE" != "" ];then
   echo "$NGINX_CERT" | sed 's/\\n/\n/g' > $NGINX_CERT_FILE
fi
if [ "$NGINX_KEY" != "" -a "$NGINX_KEY_FILE" != "" ];then
   echo "$NGINX_KEY" | sed 's/\\n/\n/g' > $NGINX_KEY_FILE
fi
if [ "$NGINX_CERT_FILE" != "" -a "$NGINX_KEY_FILE" != "" -a "$NGINX_DOMAIN" != "" -a ! -f "$NGINX_CERT_FILE" ];then
    # create self-signed certificates
    openssl req -x509 -newkey rsa:2048 -keyout "$NGINX_KEY_FILE" -out "$NGINX_CERT_FILE" -days 365 -nodes -subj "/CN=$NGINX_DOMAIN"
fi
nginx -g "daemon off;" $*

Tag summary

Content type

Image

Digest

Size

52.7 MB

Last updated

over 10 years ago

docker pull sshipway/nginx:1.9.9