Reapply www to non-www redirect
* Applying changes from 9ee3d311da
* Adjusted to new template from upstream
This commit is contained in:
parent
51191e168a
commit
a7c763d478
1 changed files with 17 additions and 4 deletions
15
nginx.tmpl
15
nginx.tmpl
|
@ -177,6 +177,9 @@
|
|||
{{- end }}
|
||||
{{- if exists $override }}
|
||||
include {{ $override }};
|
||||
{{- else }}
|
||||
{{- if (hasPrefix "www." .Host) }}
|
||||
return 301 {{ternary "http" "https" (eq .HttpsMethod "nohttps") }}://{{ trimPrefix "www." .Host }}$request_uri;
|
||||
{{- else }}
|
||||
{{- $keepalive := first (keys (groupByLabel .Containers "com.github.nginx-proxy.nginx-proxy.keepalive")) }}
|
||||
location {{ .Path }} {
|
||||
|
@ -217,6 +220,7 @@
|
|||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "upstream" }}
|
||||
upstream {{ .Upstream }} {
|
||||
|
@ -516,11 +520,20 @@ server {
|
|||
}
|
||||
|
||||
location / {
|
||||
{{- if (hasPrefix "www." $host) }}
|
||||
{{- $nonWwwHost := trimPrefix "www." $host }}
|
||||
{{- if eq $globals.external_https_port "443" }}
|
||||
return 301 https://{{ $nonWwwHost }}$request_uri;
|
||||
{{- else }}
|
||||
return 301 https://{{ $nonWwwHost }}:{{ $globals.external_https_port }}$request_uri;
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{- if eq $globals.external_https_port "443" }}
|
||||
return 301 https://$host$request_uri;
|
||||
{{- else }}
|
||||
return 301 https://$host:{{ $globals.external_https_port }}$request_uri;
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
}
|
||||
{{- end }}
|
||||
|
@ -625,7 +638,7 @@ server {
|
|||
{{- $upstream = printf "%s-%s" $upstream $sum }}
|
||||
{{- $dest = (or (first (groupByKeys $containers "Env.VIRTUAL_DEST")) "") }}
|
||||
{{- end }}
|
||||
{{- template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag "Containers" $containers) }}
|
||||
{{- template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag "Containers" $containers "HttpsMethod" $https_method) }}
|
||||
{{- end }}
|
||||
{{- if and (not (contains $paths "/")) (ne $globals.default_root_response "none")}}
|
||||
location / {
|
||||
|
|
Loading…
Reference in a new issue