Skip to content

Commit 4e4733f

Browse files
committed
Trim $host and $proto before they are used
1 parent 23a2c7d commit 4e4733f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

nginx.tmpl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ server {
9999
{{ end }}
100100

101101
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
102+
103+
{{ $host := trim $host }}
102104
{{ $is_regexp := hasPrefix "~" $host }}
103105
{{ $upstream_name := when $is_regexp (sha1 $host) $host }}
106+
104107
# {{ $host }}
105108
upstream {{ $upstream_name }} {
109+
106110
{{ range $container := $containers }}
107111
{{ $addrLen := len $container.Addresses }}
108112

@@ -131,7 +135,7 @@ upstream {{ $upstream_name }} {
131135
{{ $default_server := index (dict $host "" $default_host "default_server") $host }}
132136

133137
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}}
134-
{{ $proto := or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http" }}
138+
{{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }}
135139

136140
{{/* Get the HTTPS_METHOD defined by containers w/ the same vhost, falling back to "redirect" */}}
137141
{{ $https_method := or (first (groupByKeys $containers "Env.HTTPS_METHOD")) "redirect" }}
@@ -205,6 +209,7 @@ server {
205209
{{ else }}
206210
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
207211
{{ end }}
212+
208213
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
209214
auth_basic "Restricted {{ $host }}";
210215
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};

0 commit comments

Comments
 (0)