Updating from/to www redirect to use X-Forwarded-Proto (#7623)

This commit is contained in:
Alois 2022-01-16 17:17:28 -05:00 committed by GitHub
parent ae6ab1d5ed
commit 0bc01f7c35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -586,11 +586,17 @@ http {
request_uri = string.sub(request_uri, 1, -2) request_uri = string.sub(request_uri, 1, -2)
end 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 }} {{ if ne $all.ListenPorts.HTTPS 443 }}
{{ $redirect_port := (printf ":%v" $all.ListenPorts.HTTPS) }} {{ $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 }} {{ 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 }} {{ end }}
} }