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 }}
|
{{- end }}
|
||||||
{{- if exists $override }}
|
{{- if exists $override }}
|
||||||
include {{ $override }};
|
include {{ $override }};
|
||||||
|
{{- else }}
|
||||||
|
{{- if (hasPrefix "www." .Host) }}
|
||||||
|
return 301 {{ternary "http" "https" (eq .HttpsMethod "nohttps") }}://{{ trimPrefix "www." .Host }}$request_uri;
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{- $keepalive := first (keys (groupByLabel .Containers "com.github.nginx-proxy.nginx-proxy.keepalive")) }}
|
{{- $keepalive := first (keys (groupByLabel .Containers "com.github.nginx-proxy.nginx-proxy.keepalive")) }}
|
||||||
location {{ .Path }} {
|
location {{ .Path }} {
|
||||||
|
@ -216,6 +219,7 @@
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{- define "upstream" }}
|
{{- define "upstream" }}
|
||||||
|
@ -516,11 +520,20 @@ server {
|
||||||
}
|
}
|
||||||
|
|
||||||
location / {
|
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" }}
|
{{- if eq $globals.external_https_port "443" }}
|
||||||
return 301 https://$host$request_uri;
|
return 301 https://$host$request_uri;
|
||||||
{{- else }}
|
{{- else }}
|
||||||
return 301 https://$host:{{ $globals.external_https_port }}$request_uri;
|
return 301 https://$host:{{ $globals.external_https_port }}$request_uri;
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
@ -625,7 +638,7 @@ server {
|
||||||
{{- $upstream = printf "%s-%s" $upstream $sum }}
|
{{- $upstream = printf "%s-%s" $upstream $sum }}
|
||||||
{{- $dest = (or (first (groupByKeys $containers "Env.VIRTUAL_DEST")) "") }}
|
{{- $dest = (or (first (groupByKeys $containers "Env.VIRTUAL_DEST")) "") }}
|
||||||
{{- end }}
|
{{- 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 }}
|
{{- end }}
|
||||||
{{- if and (not (contains $paths "/")) (ne $globals.default_root_response "none")}}
|
{{- if and (not (contains $paths "/")) (ne $globals.default_root_response "none")}}
|
||||||
location / {
|
location / {
|
||||||
|
|
Loading…
Reference in a new issue