From 422be0ae8d282bb86f50dcbb1005ebb2275d995d Mon Sep 17 00:00:00 2001 From: Cristhian Rivera Date: Sun, 16 Oct 2022 13:11:59 +0200 Subject: [PATCH] Allow redirection to GeoServer webapp from the ROOT webapp --- Dockerfile | 1 + README.md | 5 +++++ startup.sh | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/Dockerfile b/Dockerfile index a40192d..4de6a4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,6 +31,7 @@ ENV STABLE_PLUGIN_URL=$STABLE_PLUGIN_URL ENV ADDITIONAL_LIBS_DIR=/opt/additional_libs/ ENV ADDITIONAL_FONTS_DIR=/opt/additional_fonts/ ENV SKIP_DEMO_DATA=false +ENV ROOT_WEBAPP_REDIRECT=false # see https://docs.geoserver.org/stable/en/user/production/container.html ENV CATALINA_OPTS="\$EXTRA_JAVA_OPTS \ diff --git a/README.md b/README.md index a7470d6..2ad7a58 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,11 @@ using the same data directory. This image populates GeoServer with demo data by default. For production scenarios this is typically not desired. The environment variable `SKIP_DEMO_DATA` can be set to `true` to create an empty GeoServer. +### How to issue a redirect from the root ("/") to GeoServer web interface ("/geoserver/web")? + +By default, the ROOT webapp is not available which makes requests to the root endpoint "/" return a 404 error. +The environment variable `ROOT_WEBAPP_REDIRECT` can be set to `true` to issue a permanent redirect to the web interface. + ### How to download and install additional extensions on startup? The ``startup.sh`` script allows some customization on startup: diff --git a/startup.sh b/startup.sh index b8a3ec8..548623d 100755 --- a/startup.sh +++ b/startup.sh @@ -6,6 +6,22 @@ if [ "${SKIP_DEMO_DATA}" = "true" ]; then unset GEOSERVER_REQUIRE_FILE fi +## Add a permanent redirect (HTTP 301) from the root webapp ("/") to geoserver web interface ("/geoserver/web") +if [ "${ROOT_WEBAPP_REDIRECT}" = "true" ]; then + if [ ! -d $CATALINA_HOME/webapps/ROOT ]; then + mkdir $CATALINA_HOME/webapps/ROOT + fi + + cat > $CATALINA_HOME/webapps/ROOT/index.jsp << EOF +<% + final String redirectURL = "/geoserver/web/"; + response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); + response.setHeader("Location", redirectURL); +%> +EOF +fi + + ## install release data directory if needed before starting tomcat if [ ! -z "$GEOSERVER_REQUIRE_FILE" ] && [ ! -f "$GEOSERVER_REQUIRE_FILE" ]; then echo "Initialize $GEOSERVER_DATA_DIR from data directory included in geoserver.war"