From 3d80759a21a9c0d1923cc69e7e94885179925b8c Mon Sep 17 00:00:00 2001 From: Julian Reinhardt Date: Thu, 4 Nov 2021 10:08:15 +0100 Subject: [PATCH 1/2] Renames the $upstream variables and does not append $request_ui if capture group exists in location --- backend/templates/_location.conf | 4 ++-- docker/rootfs/etc/nginx/conf.d/include/proxy.conf | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/templates/_location.conf b/backend/templates/_location.conf index 2b85793..7c84471 100644 --- a/backend/templates/_location.conf +++ b/backend/templates/_location.conf @@ -1,11 +1,11 @@ location {{ path }} { - set $upstream {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }}$request_uri; + set $targetUri {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }}{% unless path contains "(" %}$request_uri{% endunless %}; proxy_set_header Host $host; proxy_set_header X-Forwarded-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Real-IP $remote_addr; - proxy_pass $upstream; + proxy_pass $targetUri; {% if access_list_id > 0 %} {% if access_list.items.length > 0 %} diff --git a/docker/rootfs/etc/nginx/conf.d/include/proxy.conf b/docker/rootfs/etc/nginx/conf.d/include/proxy.conf index 1fda72b..ac5b306 100644 --- a/docker/rootfs/etc/nginx/conf.d/include/proxy.conf +++ b/docker/rootfs/etc/nginx/conf.d/include/proxy.conf @@ -1,9 +1,9 @@ -set $upstream $forward_scheme://$server:$port$request_uri; +set $targetUri $forward_scheme://$server:$port$request_uri; add_header X-Served-By $host; proxy_set_header Host $host; proxy_set_header X-Forwarded-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Real-IP $remote_addr; -proxy_pass $upstream; +proxy_pass $targetUri; From c203d1a0d810e527eed9f68f84b349b7fc4ccb5b Mon Sep 17 00:00:00 2001 From: Julian Reinhardt Date: Sat, 6 Nov 2021 13:38:02 +0100 Subject: [PATCH 2/2] Requires ~() in location to remove $request_uri and removes $request_uri if it is just a slash --- backend/templates/_location.conf | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/templates/_location.conf b/backend/templates/_location.conf index 7c84471..f286fda 100644 --- a/backend/templates/_location.conf +++ b/backend/templates/_location.conf @@ -1,5 +1,10 @@ location {{ path }} { - set $targetUri {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }}{% unless path contains "(" %}$request_uri{% endunless %}; + set $targetUri {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }}; + {% unless path contains "~" and path contains "(" and path contains ")" %} + if ($request_uri != /){ + set $targetUri $targetUri$request_uri; + } + {% endunless %} proxy_set_header Host $host; proxy_set_header X-Forwarded-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme;