From a392bf2ead657d075564d5839ba12505fa5e2752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Cant=C3=B9?= Date: Thu, 1 Feb 2024 13:35:39 +0100 Subject: [PATCH] set nginx host with custom port --- docker/nginx/docker-entrypoint.sh | 17 ++++++++++++++--- docker/nginx/geonode.conf.envsubst | 4 ++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/docker/nginx/docker-entrypoint.sh b/docker/nginx/docker-entrypoint.sh index e6bec7a..d092109 100644 --- a/docker/nginx/docker-entrypoint.sh +++ b/docker/nginx/docker-entrypoint.sh @@ -34,8 +34,18 @@ fi if [ -z "${HTTPS_HOST}" ]; then HTTP_SCHEME="http" + if [ $HTTP_PORT = "80" ]; then + PUBLIC_HOST=${HTTP_HOST} + else + PUBLIC_HOST="$HTTP_HOST:$HTTP_PORT" + fi else HTTP_SCHEME="https" + if [ $HTTPS_PORT = "443" ]; then + PUBLIC_HOST=${HTTPS_HOST} + else + PUBLIC_HOST="$HTTPS_HOST:$HTTPS_PORT" + fi fi export HTTP_SCHEME=${HTTP_SCHEME:-http} @@ -43,11 +53,12 @@ export GEONODE_LB_HOST_IP=${GEONODE_LB_HOST_IP:-django} export GEONODE_LB_PORT=${GEONODE_LB_PORT:-8000} export GEOSERVER_LB_HOST_IP=${GEOSERVER_LB_HOST_IP:-geoserver} export GEOSERVER_LB_PORT=${GEOSERVER_LB_PORT:-8080} +export PUBLIC_HOST=${PUBLIC_HOST} echo "Replacing environement variables" -envsubst '\$HTTP_HOST \$HTTPS_HOST \$HTTP_SCHEME \$GEONODE_LB_HOST_IP \$GEONODE_LB_PORT \$GEOSERVER_LB_HOST_IP \$GEOSERVER_LB_PORT \$RESOLVER' < /etc/nginx/nginx.conf.envsubst > /etc/nginx/nginx.conf -envsubst '\$HTTP_HOST \$HTTPS_HOST \$HTTP_SCHEME \$GEONODE_LB_HOST_IP \$GEONODE_LB_PORT \$GEOSERVER_LB_HOST_IP \$GEOSERVER_LB_PORT \$RESOLVER' < /etc/nginx/nginx.https.available.conf.envsubst > /etc/nginx/nginx.https.available.conf -envsubst '\$HTTP_HOST \$HTTPS_HOST \$HTTP_SCHEME \$GEONODE_LB_HOST_IP \$GEONODE_LB_PORT \$GEOSERVER_LB_HOST_IP \$GEOSERVER_LB_PORT' < /etc/nginx/sites-enabled/geonode.conf.envsubst > /etc/nginx/sites-enabled/geonode.conf +envsubst '\$HTTP_HOST \$PUBLIC_HOST \$HTTPS_HOST \$HTTP_SCHEME \$GEONODE_LB_HOST_IP \$GEONODE_LB_PORT \$GEOSERVER_LB_HOST_IP \$GEOSERVER_LB_PORT \$RESOLVER' < /etc/nginx/nginx.conf.envsubst > /etc/nginx/nginx.conf +envsubst '\$HTTP_HOST \$PUBLIC_HOST \$HTTPS_HOST \$HTTP_SCHEME \$GEONODE_LB_HOST_IP \$GEONODE_LB_PORT \$GEOSERVER_LB_HOST_IP \$GEOSERVER_LB_PORT \$RESOLVER' < /etc/nginx/nginx.https.available.conf.envsubst > /etc/nginx/nginx.https.available.conf +envsubst '\$HTTP_HOST \$PUBLIC_HOST \$HTTPS_HOST \$HTTP_SCHEME \$GEONODE_LB_HOST_IP \$GEONODE_LB_PORT \$GEOSERVER_LB_HOST_IP \$GEOSERVER_LB_PORT' < /etc/nginx/sites-enabled/geonode.conf.envsubst > /etc/nginx/sites-enabled/geonode.conf echo "Enabling or not https configuration" if [ -z "${HTTPS_HOST}" ]; then diff --git a/docker/nginx/geonode.conf.envsubst b/docker/nginx/geonode.conf.envsubst index 1176ce2..2725ffc 100644 --- a/docker/nginx/geonode.conf.envsubst +++ b/docker/nginx/geonode.conf.envsubst @@ -105,8 +105,8 @@ location / { add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, OPTIONS"; proxy_redirect off; - proxy_set_header Host $host; - proxy_set_header Origin $HTTP_SCHEME://$host; + proxy_set_header Host $PUBLIC_HOST; + proxy_set_header Origin $HTTP_SCHEME://$PUBLIC_HOST; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Host $server_name; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;