From 17c62ba320369ed7916ee217814e38b5598acb36 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Fri, 30 Jun 2023 15:22:29 -0400 Subject: [PATCH] Make php-fpm server name an env var (#4) --- nginx/Dockerfile | 9 ++++++--- nginx/conf/nginx.conf | 2 +- nginx/docker-entrypoint.sh | 11 +++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 nginx/docker-entrypoint.sh diff --git a/nginx/Dockerfile b/nginx/Dockerfile index e502bb6..8488214 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,9 +1,12 @@ ARG NGINX_VERSION=1.25.1 - FROM nginx:${NGINX_VERSION} +ENV PHP_FPM_HOST=php-fpm + COPY conf/fastcgi_params /etc/nginx/fastcgi_params -COPY conf/nginx.conf /etc/nginx/nginx.conf +COPY conf/nginx.conf /etc/nginx/nginx.conf.template + +COPY docker-entrypoint.sh / RUN rm /docker-entrypoint.d/* /etc/nginx/conf.d/*.conf && \ - mkdir -p /code/web + chmod +x /docker-entrypoint.sh diff --git a/nginx/conf/nginx.conf b/nginx/conf/nginx.conf index 48ee19b..c2a5c47 100644 --- a/nginx/conf/nginx.conf +++ b/nginx/conf/nginx.conf @@ -25,7 +25,7 @@ http { fastcgi_read_timeout 600; upstream php_fpm_service { - server php-fpm:9000; + server ${PHP_FPM_HOST}:9000; } server { diff --git a/nginx/docker-entrypoint.sh b/nginx/docker-entrypoint.sh new file mode 100644 index 0000000..b4e5cf3 --- /dev/null +++ b/nginx/docker-entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/env bash + +set -e + +envsubst '${PHP_FPM_HOST}' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf + +if [[ "$1" == -* ]]; then + set -- nginx -g daemon off; "$@" +fi + +exec "$@"