From 0bc01f7c35410ce5cb07ee86ab530e99ae352026 Mon Sep 17 00:00:00 2001 From: Alois Date: Sun, 16 Jan 2022 17:17:28 -0500 Subject: [PATCH] Updating from/to www redirect to use X-Forwarded-Proto (#7623) --- rootfs/etc/nginx/template/nginx.tmpl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 954d07fd77..07e36925bc 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -586,11 +586,17 @@ http { request_uri = string.sub(request_uri, 1, -2) end + {{ if $cfg.UseForwardedHeaders }} + local redirectScheme = ngx.var.http_x_forwarded_proto + {{ else }} + local redirectScheme = ngx.var.scheme + {{ end }} + {{ if ne $all.ListenPorts.HTTPS 443 }} {{ $redirect_port := (printf ":%v" $all.ListenPorts.HTTPS) }} - return string.format("%s://%s%s%s", ngx.var.scheme, "{{ $redirect.To }}", "{{ $redirect_port }}", request_uri) + return string.format("%s://%s%s%s", redirectScheme, "{{ $redirect.To }}", "{{ $redirect_port }}", request_uri) {{ else }} - return string.format("%s://%s%s", ngx.var.scheme, "{{ $redirect.To }}", request_uri) + return string.format("%s://%s%s", redirectScheme, "{{ $redirect.To }}", request_uri) {{ end }} }