From ad8598d04b5c9aba437f1106aeabe48e5e2e501b Mon Sep 17 00:00:00 2001 From: Mossroy Date: Sat, 25 Feb 2023 14:40:13 +0100 Subject: [PATCH 1/2] Allow to replace "app" server name in nginx by value of an env var By default, nginx sends php requests to an upstream "app" server. While keeping this default behavior, this commit allows the user to override this server name at runtime, by setting an APP_SERVERNAME env var to the nginx container --- src/web-nginx/Dockerfile | 12 +++++++++++- src/web-nginx/nginx.conf | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/web-nginx/Dockerfile b/src/web-nginx/Dockerfile index 50d976b..234a60f 100644 --- a/src/web-nginx/Dockerfile +++ b/src/web-nginx/Dockerfile @@ -2,4 +2,14 @@ FROM nginx:alpine HEALTHCHECK CMD curl --fail http://localhost/tt-rss/index.php || exit 1 -COPY nginx.conf /etc/nginx/nginx.conf +COPY nginx.conf /etc/nginx/templates/nginx.conf.template + +# By default, nginx will send the php requests to "app" server, but this server +# name can be overridden at runtime by passing an APP_SERVERNAME env var +ENV APP_SERVERNAME=${APP_SERVERNAME:-app} + +# It's necessary to set the following NGINX_ENVSUBST_OUTPUT_DIR env var to tell +# nginx to replace the env vars of /etc/nginx/templates/nginx.conf.template +# and put the result in /etc/nginx/nginx.conf (instead of /etc/nginx/conf.d/nginx.conf) +# See https://github.com/docker-library/docs/tree/master/nginx#using-environment-variables-in-nginx-configuration-new-in-119 +ENV NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx diff --git a/src/web-nginx/nginx.conf b/src/web-nginx/nginx.conf index 131dd79..f189785 100644 --- a/src/web-nginx/nginx.conf +++ b/src/web-nginx/nginx.conf @@ -17,7 +17,7 @@ http { index index.php; upstream app { - server app:9000; + server ${APP_SERVERNAME}:9000; } server { From b8136830a10e3341ff1c2a2e2c38579391065fd2 Mon Sep 17 00:00:00 2001 From: Mossroy Date: Sat, 25 Feb 2023 15:11:39 +0100 Subject: [PATCH 2/2] Rename env var to APP_UPSTREAM --- src/web-nginx/Dockerfile | 4 ++-- src/web-nginx/nginx.conf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/web-nginx/Dockerfile b/src/web-nginx/Dockerfile index 234a60f..b92f8f2 100644 --- a/src/web-nginx/Dockerfile +++ b/src/web-nginx/Dockerfile @@ -5,8 +5,8 @@ HEALTHCHECK CMD curl --fail http://localhost/tt-rss/index.php || exit 1 COPY nginx.conf /etc/nginx/templates/nginx.conf.template # By default, nginx will send the php requests to "app" server, but this server -# name can be overridden at runtime by passing an APP_SERVERNAME env var -ENV APP_SERVERNAME=${APP_SERVERNAME:-app} +# name can be overridden at runtime by passing an APP_UPSTREAM env var +ENV APP_UPSTREAM=${APP_UPSTREAM:-app} # It's necessary to set the following NGINX_ENVSUBST_OUTPUT_DIR env var to tell # nginx to replace the env vars of /etc/nginx/templates/nginx.conf.template diff --git a/src/web-nginx/nginx.conf b/src/web-nginx/nginx.conf index f189785..f7d47c4 100644 --- a/src/web-nginx/nginx.conf +++ b/src/web-nginx/nginx.conf @@ -17,7 +17,7 @@ http { index index.php; upstream app { - server ${APP_SERVERNAME}:9000; + server ${APP_UPSTREAM}:9000; } server {