From f40a8697bc61a724a9b4520904de653242c5a86d Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 Sep 2023 13:21:09 -0400 Subject: [PATCH] fixup --- Dockerfile | 9 +++++++-- docker-entrypoint.sh | 7 +++++++ nginx.conf | 6 +----- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 7c8976c..1fa3a31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,12 @@ # Start from the official Nginx image FROM nginx:alpine -# Copy our custom Nginx configuration -COPY nginx.conf /etc/nginx/nginx.conf +# Copy our custom Nginx configuration and script +COPY nginx.conf /etc/nginx/nginx.conf.template +COPY docker-entrypoint.sh /docker-entrypoint.sh +# Make the script executable +RUN chmod +x /docker-entrypoint.sh + +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..e13d49a --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Use envsubst to replace environment variables in nginx.conf.template and output to nginx.conf +envsubst '$BACKEND_ADDRESS,$BACKEND_PORT' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf + +# Start nginx in the foreground +exec nginx -g 'daemon off;' diff --git a/nginx.conf b/nginx.conf index 573518f..47f8ec1 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,10 +1,6 @@ user nginx; worker_processes 1; -# Load environment variables -env BACKEND_ADDRESS; -env BACKEND_PORT; - events { worker_connections 1024; } @@ -17,7 +13,7 @@ http { listen 80; location / { - # Use the environment variables for the proxy pass + # Use the placeholders for the proxy pass (these will be replaced by envsubst) proxy_pass http://$BACKEND_ADDRESS:$BACKEND_PORT; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;