This is an automated email from the ASF dual-hosted git repository.
wenming pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 93901a93a fix: fix ui redirect error when behind proxy (#12566)
93901a93a is described below
commit 93901a93a2218f5a6c675024a61e9070e46e9365
Author: feranwq <[email protected]>
AuthorDate: Thu Sep 18 07:44:12 2025 +0800
fix: fix ui redirect error when behind proxy (#12566)
---
apisix/cli/ngx_tpl.lua | 5 +++++
t/cli/test_admin_ui.sh | 11 +++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua
index 1129900f6..18b77fd3c 100644
--- a/apisix/cli/ngx_tpl.lua
+++ b/apisix/cli/ngx_tpl.lua
@@ -651,6 +651,11 @@ http {
{% if enable_admin_ui then %}
location = /ui {
+ # Fixes incorrect redirect URLs when Nginx is behind a reverse
proxy.
+ # By default, Nginx generates an absolute URL (e.g.,
http://backend:9180/ui/).
+ # Setting this to "off" generates a relative URL (e.g., /ui/),
which the browser
+ # correctly resolves against the public-facing domain.
+ absolute_redirect off;
return 301 /ui/;
}
location ^~ /ui/ {
diff --git a/t/cli/test_admin_ui.sh b/t/cli/test_admin_ui.sh
index 91b3ce423..2dd2cb465 100755
--- a/t/cli/test_admin_ui.sh
+++ b/t/cli/test_admin_ui.sh
@@ -33,14 +33,21 @@ fi
make run
-## check /ui redirects to /ui/
-
+## check /ui redirects to /ui/ with 301
code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
http://127.0.0.1:9180/ui)
if [ ! $code -eq 301 ]; then
echo "failed: failed to redirect /ui to /ui/"
exit 1
fi
+## check /ui redirects to /ui/ with correct Location header
+location_header=$(curl -k -i -m 20 -s http://127.0.0.1:9180/ui | grep -i
'^Location:' | awk -F': ' '{print $2}' | tr -d '\r')
+
+if [ "${location_header}" != "/ui/" ]; then
+ echo "failed: incorrect redirect Location header when accessing /ui,
expected /ui/, got ${location_header}"
+ exit 1
+fi
+
## check /ui/ accessible
mkdir -p ui/assets