From 5ab6c8910c818090be30f31ea1b1a37ea335d8b6 Mon Sep 17 00:00:00 2001 From: thelittlefireman Date: Tue, 21 May 2024 01:55:48 +0200 Subject: [PATCH] Fix redirect issue when docker is behind an other reverse proxy --- rootfs/etc/cont-init.d/03-config.sh | 8 +++++++- rootfs/tpls/etc/nginx/nginx.conf | 10 +++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/rootfs/etc/cont-init.d/03-config.sh b/rootfs/etc/cont-init.d/03-config.sh index 06beb36..3f935f2 100644 --- a/rootfs/etc/cont-init.d/03-config.sh +++ b/rootfs/etc/cont-init.d/03-config.sh @@ -38,6 +38,12 @@ APC_SHM_SIZE=${APC_SHM_SIZE:-128M} REAL_IP_FROM=${REAL_IP_FROM:-0.0.0.0/32} REAL_IP_HEADER=${REAL_IP_HEADER:-X-Forwarded-For} LOG_IP_VAR=${LOG_IP_VAR:-remote_addr} +if [ -z "$SUBDIR" ] +then + REDIRECT_URL='$scheme://$host' +else + REDIRECT_URL=$SUBDIR +fi HSTS_HEADER=${HSTS_HEADER:-max-age=15768000; includeSubDomains} XFRAME_OPTS_HEADER=${XFRAME_OPTS_HEADER:-SAMEORIGIN} @@ -83,7 +89,7 @@ sed -e "s/@UPLOAD_MAX_SIZE@/$UPLOAD_MAX_SIZE/g" \ -e "s/@HSTS_HEADER@/$HSTS_HEADER/g" \ -e "s/@XFRAME_OPTS_HEADER@/$XFRAME_OPTS_HEADER/g" \ -e "s/@RP_HEADER@/$RP_HEADER/g" \ - -e "s#@SUBDIR@#$SUBDIR#g" \ + -e "s#@REDIRECT_URL@#$REDIRECT_URL#g" \ /tpls/etc/nginx/nginx.conf >/etc/nginx/nginx.conf if [ "$LISTEN_IPV6" != "true" ]; then diff --git a/rootfs/tpls/etc/nginx/nginx.conf b/rootfs/tpls/etc/nginx/nginx.conf index f46157e..31a123b 100644 --- a/rootfs/tpls/etc/nginx/nginx.conf +++ b/rootfs/tpls/etc/nginx/nginx.conf @@ -125,7 +125,7 @@ http { # Handle Microsoft DAV clients location = / { if ( $http_user_agent ~ ^DavClnt ) { - return 302 @SUBDIR@/remote.php/webdav/$is_args$args; + return 302 @REDIRECT_URL@/remote.php/webdav/$is_args$args; } } @@ -137,10 +137,10 @@ http { location ^~ /.well-known { location = /.well-known/carddav { - return 301 @SUBDIR@/remote.php/dav/; + return 301 @REDIRECT_URL@/remote.php/dav/; } location = /.well-known/caldav { - return 301 @SUBDIR@/remote.php/dav/; + return 301 @REDIRECT_URL@/remote.php/dav/; } location /.well-known/acme-challenge { try_files $uri $uri/ =404; @@ -148,7 +148,7 @@ http { location /.well-known/pki-validation { try_files $uri $uri/ =404; } - return 301 @SUBDIR@/index.php$request_uri; + return 301 @REDIRECT_URL@/index.php$request_uri; } location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { @@ -219,7 +219,7 @@ http { # Rule borrowed from `.htaccess` location /remote { - return 301 @SUBDIR@/remote.php$request_uri; + return 301 @REDIRECT_URL@/remote.php$request_uri; } location / {