Skip to content

Commit

Permalink
Replace request_uri
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Aug 20, 2020
1 parent 9167865 commit 063deb5
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions rootfs/etc/nginx/template/nginx.tmpl
Expand Up @@ -549,12 +549,21 @@ http {
}
{{ end }}

{{ if ne $all.ListenPorts.HTTPS 443 }}
{{ $redirect_port := (printf ":%v" $all.ListenPorts.HTTPS) }}
return {{ $all.Cfg.HTTPRedirectCode }} $scheme://{{ $redirect.To }}{{ $redirect_port }}$request_uri;
{{ else }}
return {{ $all.Cfg.HTTPRedirectCode }} $scheme://{{ $redirect.To }}$request_uri;
{{ end }}
content_by_lua_block {
local request_uri = ngx.var.request_uri
if string.sub(request_uri, -1) == "/" then
request_uri = string.sub(request_uri, 1, -2)
end

{{ if ne $all.ListenPorts.HTTPS 443 }}
{{ $redirect_port := (printf ":%v" $all.ListenPorts.HTTPS) }}
local uri = string_format("%s://%s%s%s", ngx.var.scheme, {{ $redirect.To }}, {{ $redirect_port }}, request_uri)
{{ else }}
local uri = string_format("%s://%s%s", ngx.var.scheme, {{ $redirect.To }}, request_uri)
{{ end }}

ngx.redirect(uri, {{ $all.Cfg.HTTPRedirectCode }})
}
}
## end server {{ $redirect.From }}
{{ end }}
Expand Down

0 comments on commit 063deb5

Please sign in to comment.