adding backend port env var to nginx

This commit is contained in:
2025-11-20 22:13:58 +00:00
parent dc09ddefca
commit df2beb7b1d
4 changed files with 5 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ services:
container_name: nginx container_name: nginx
environment: environment:
BACKEND_HOST: "${BACKEND_HOST}" # from .env BACKEND_HOST: "${BACKEND_HOST}" # from .env
BACKEND_PORT: "${BACKEND_PORT}" # from .env
DOMAIN: "${DOMAIN}" # from .env DOMAIN: "${DOMAIN}" # from .env
restart: unless-stopped restart: unless-stopped
depends_on: depends_on:

View File

@@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y gettext-base
# Replace variables at build time # Replace variables at build time
ENV BACKEND_HOST=backend ENV BACKEND_HOST=backend
ENV BACKEND_PORT=8080
ENV DOMAIN=example.com ENV DOMAIN=example.com
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -4,10 +4,10 @@ set -e
# Check if certificate exists # Check if certificate exists
if [ -f "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" ] && [ -f "/etc/letsencrypt/live/$DOMAIN/privkey.pem" ]; then if [ -f "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" ] && [ -f "/etc/letsencrypt/live/$DOMAIN/privkey.pem" ]; then
echo "Certificates found. Using production nginx config." echo "Certificates found. Using production nginx config."
envsubst '$BACKEND_HOST $DOMAIN' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf envsubst '$BACKEND_HOST $BACKEND_PORT $DOMAIN' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf
else else
echo "Certificates NOT found. Using setup nginx config." echo "Certificates NOT found. Using setup nginx config."
envsubst '$BACKEND_HOST $DOMAIN' < /etc/nginx/nginx_setup.conf.template > /etc/nginx/nginx.conf envsubst '$BACKEND_HOST $BACKEND_PORT $DOMAIN' < /etc/nginx/nginx_setup.conf.template > /etc/nginx/nginx.conf
fi fi
# Start nginx # Start nginx

View File

@@ -49,7 +49,7 @@ http {
} }
location /posts/ { location /posts/ {
proxy_pass http://$BACKEND_HOST:8080/posts; proxy_pass http://$BACKEND_HOST:$BACKEND_PORT/posts;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;