Skip to content

Commit

Permalink
Merge pull request #1769 from aledbf/port-redirect
Browse files Browse the repository at this point in the history
Use custom https port in redirects
  • Loading branch information
aledbf authored Nov 30, 2017
2 parents 2e3c7e2 + be185b9 commit 120bb1d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,13 @@ http {
{{ end }}
{{ end }}
server_name {{ $hostname }};

{{ if ne $all.ListenPorts.HTTPS 443 }}
{{ $redirect_port := (printf ":%v" $all.ListenPorts.HTTPS) }}
return 301 $scheme://{{ $to }}{{ $redirect_port }}$request_uri;
{{ else }}
return 301 $scheme://{{ $to }}$request_uri;
{{ end }}
}
{{ end }}

Expand Down Expand Up @@ -679,7 +685,12 @@ stream {
{{ if (or $location.Rewrite.ForceSSLRedirect (and (not (empty $server.SSLCertificate)) $location.Rewrite.SSLRedirect)) }}
# enforce ssl on server side
if ($pass_access_scheme = http) {
{{ if ne $all.ListenPorts.HTTPS 443 }}
{{ $redirect_port := (printf ":%v" $all.ListenPorts.HTTPS) }}
return 301 https://$best_http_host{{ $redirect_port }}$request_uri;
{{ else }}
return 301 https://$best_http_host$request_uri;
{{ end }}
}
{{ end }}

Expand Down

0 comments on commit 120bb1d

Please sign in to comment.