Skip to content

Commit e3f50b6

Browse files
committed
Forward the port where Nginx is exposed to Django
1 parent fded69b commit e3f50b6

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

docker/nginx/docker-entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,26 @@ fi
3434

3535
if [ -z "${HTTPS_HOST}" ]; then
3636
HTTP_SCHEME="http"
37+
if [ $HTTP_PORT = "80" ]; then
38+
PUBLIC_HOST=${HTTP_HOST}
39+
else
40+
PUBLIC_HOST="$HTTP_HOST:$HTTP_PORT"
41+
fi
3742
else
3843
HTTP_SCHEME="https"
44+
if [ $HTTPS_PORT = "443" ]; then
45+
PUBLIC_HOST=${HTTPS_HOST}
46+
else
47+
PUBLIC_HOST="$HTTPS_HOST:$HTTPS_PORT"
48+
fi
3949
fi
4050

4151
export HTTP_SCHEME=${HTTP_SCHEME:-http}
4252
export GEONODE_LB_HOST_IP=${GEONODE_LB_HOST_IP:-django}
4353
export GEONODE_LB_PORT=${GEONODE_LB_PORT:-8000}
4454
export GEOSERVER_LB_HOST_IP=${GEOSERVER_LB_HOST_IP:-geoserver}
4555
export GEOSERVER_LB_PORT=${GEOSERVER_LB_PORT:-8080}
56+
export PUBLIC_HOST=${PUBLIC_HOST}
4657

4758
defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))
4859

@@ -51,6 +62,7 @@ envsubst "$defined_envs" < /etc/nginx/nginx.conf.envsubst > /etc/nginx/nginx.con
5162
envsubst "$defined_envs" < /etc/nginx/nginx.https.available.conf.envsubst > /etc/nginx/nginx.https.available.conf
5263
envsubst "$defined_envs" < /etc/nginx/sites-enabled/geonode.conf.envsubst > /etc/nginx/sites-enabled/geonode.conf
5364

65+
5466
echo "Enabling or not https configuration"
5567
if [ -z "${HTTPS_HOST}" ]; then
5668
echo "" > /etc/nginx/nginx.https.enabled.conf

docker/nginx/geonode.conf.envsubst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ location / {
106106
add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, OPTIONS";
107107

108108
proxy_redirect off;
109-
proxy_set_header Host $host;
110-
proxy_set_header Origin $HTTP_SCHEME://$host;
109+
proxy_set_header Host $PUBLIC_HOST;
110+
proxy_set_header Origin $HTTP_SCHEME://$PUBLIC_HOST;
111111
proxy_set_header X-Real-IP $remote_addr;
112112
proxy_set_header X-Forwarded-Host $server_name;
113113
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

0 commit comments

Comments
 (0)