From 2b41ab4def6bdab7c475cae16e3ba7e208fcaa17 Mon Sep 17 00:00:00 2001 From: Johannes Schickling Date: Sun, 19 Jun 2016 16:21:28 +0200 Subject: [PATCH] better nginx config --- nginx-envtpl/README.md | 61 +++++++++++++++++++++++++++++++++++++- nginx-envtpl/entrypoint.sh | 6 +++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/nginx-envtpl/README.md b/nginx-envtpl/README.md index 068e6e7..336aea8 100644 --- a/nginx-envtpl/README.md +++ b/nginx-envtpl/README.md @@ -50,4 +50,63 @@ http { } } -``` \ No newline at end of file +``` + +### Alternative: Template via `$NGINX_CONFIG_TEMPLATE` environment variable + +Instead of mounting a `nginx.conf.tpl` file via a volume, you can also pass in the template via the `$NGINX_CONFIG_TEMPLATE` environment variable. + +Here is an `docker-compose.yml` example segment: + + +```yaml +proxy: + image: schickling/nginx-envtpl + environment: + NGINX_WORKER_RLIMIT_NOFILE: 96000 + NGINX_WORKER_CONNECTIONS: 10000 + NGINX_BACKLOG: 10000 + NGINX_PROXY_ADDR: "http://example.com/" + NGINX_CONFIG_TEMPLATE: > + worker_processes auto; + worker_rlimit_nofile {{ NGINX_WORKER_RLIMIT_NOFILE }}; + error_log /dev/stdout info; + + events { + worker_connections {{ NGINX_WORKER_CONNECTIONS }}; + use epoll; + multi_accept on; + } + + http { + + proxy_cache_path /tmp/nginx levels=1:2 keys_zone=my_zone:10m inactive=60m; + + access_log /dev/stdout; + + server { + + listen 80 backlog={{ NGINX_BACKLOG }}; + root /usr/share/nginx/html/; + index index.html; + + server_name localhost; + + charset utf-8; + + location / { + proxy_pass {{ NGINX_PROXY_ADDR }}; + proxy_cache my_zone; + proxy_cache_methods POST; + proxy_cache_key "$request_uri|$request_body"; + proxy_cache_valid 5s; + proxy_cache_use_stale error timeout updating; + + add_header X-Proxy-Cache $upstream_cache_status; + } + } + + } + ports: + - "80:80" +``` diff --git a/nginx-envtpl/entrypoint.sh b/nginx-envtpl/entrypoint.sh index b3dfda1..c271c2e 100755 --- a/nginx-envtpl/entrypoint.sh +++ b/nginx-envtpl/entrypoint.sh @@ -1,5 +1,9 @@ #!/bin/sh -envtpl /etc/nginx/nginx.conf.tpl +if [[ ! -z $NGINX_CONFIG_TEMPLATE ]]; then + envtpl < $NGINX_CONFIG_TEMPLATE > /etc/nginx/nginx.conf +else + envtpl /etc/nginx/nginx.conf.tpl +fi exec "$@"