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

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

View File

@@ -4,10 +4,10 @@ set -e
# Check if certificate exists
if [ -f "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" ] && [ -f "/etc/letsencrypt/live/$DOMAIN/privkey.pem" ]; then
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
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
# Start nginx

View File

@@ -49,7 +49,7 @@ http {
}
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 X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;