@@ -241,6 +241,18 @@ upstream {{ $upstream_name }} {
241
241
242
242
{{ $is_https := (and (ne $https_method "nohttps") (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert))) }}
243
243
244
+ {{/* Get the best matching vhost.d include file */}}
245
+ {{ $vhostFile := closest (dir "/etc/nginx/vhost.d") ($host) }}
246
+ {{ $vhostFile := when (ne $vhostFile "") (print "/etc/nginx/vhost.d/" $vhostFile) "" }}
247
+
248
+ {{/* Get the best matching vhost.d location include file */}}
249
+ {{ $vhostLocationFile := closest (dir "/etc/nginx/vhost.d") (print $host "_location") }}
250
+ {{ $vhostLocationFile := when (ne $vhostLocationFile "") (print "/etc/nginx/vhost.d/" $vhostLocationFile) "" }}
251
+
252
+ {{/* Get the best matching htpasswd file */}}
253
+ {{ $htpasswdFile := closest (dir "/etc/nginx/htpasswd") $host }}
254
+ {{ $htpasswdFile := when (ne $htpasswdFile "") (print "/etc/nginx/htpasswd/" $htpasswdFile) "" }}
255
+
244
256
{{ if $is_https }}
245
257
246
258
{{ if eq $https_method "redirect" }}
@@ -303,8 +315,8 @@ server {
303
315
add_header Strict-Transport-Security "{{ trim $hsts }}" always;
304
316
{{ end }}
305
317
306
- {{ if (exists (printf "/etc/nginx/vhost.d/%s " $host )) }}
307
- include {{printf "/etc/nginx/vhost.d/%s" $host }};
318
+ {{ if (and (not (hasSuffix "_location " $vhostFile)) (exists $vhostFile )) }}
319
+ include {{$vhostFile }};
308
320
{{ else if (exists "/etc/nginx/vhost.d/default") }}
309
321
include /etc/nginx/vhost.d/default;
310
322
{{ end }}
@@ -323,12 +335,12 @@ server {
323
335
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
324
336
{{ end }}
325
337
326
- {{ if( exists(printf "/etc/nginx/htpasswd/%s" $host)) }}
338
+ {{ if exists$htpasswdFile }}
327
339
auth_basic"Restricted {{ $host }}";
328
- auth_basic_user_file{{(printf "/etc/nginx/htpasswd/%s" $host) }};
340
+ auth_basic_user_file{{$htpasswdFile }};
329
341
{{ end }}
330
- {{ if (exists (printf "/etc/nginx/vhost.d/%s_location " $host )) }}
331
- include {{printf "/etc/nginx/vhost.d/%s_location" $host }};
342
+ {{ if (and (hasSuffix "_location " $vhostLocationFile) (exists $vhostLocationFile )) }}
343
+ include {{$vhostLocationFile }};
332
344
{{ else if (exists "/etc/nginx/vhost.d/default_location") }}
333
345
include /etc/nginx/vhost.d/default_location;
334
346
{{ end }}
@@ -352,8 +364,8 @@ server {
352
364
include /etc/nginx/network_internal.conf;
353
365
{{ end }}
354
366
355
- {{ if (exists (printf "/etc/nginx/vhost.d/%s " $host )) }}
356
- include {{printf "/etc/nginx/vhost.d/%s" $host }};
367
+ {{ if (and (not (hasSuffix "_location " $vhostFile)) (exists $vhostFile )) }}
368
+ include {{$vhostFile }};
357
369
{{ else if (exists "/etc/nginx/vhost.d/default") }}
358
370
include /etc/nginx/vhost.d/default;
359
371
{{ end }}
@@ -371,12 +383,13 @@ server {
371
383
{{ else }}
372
384
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
373
385
{{ end }}
374
- {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
386
+
387
+ {{ if exists $htpasswdFile }}
375
388
auth_basic"Restricted {{ $host }}";
376
- auth_basic_user_file{{(printf "/etc/nginx/htpasswd/%s" $host) }};
389
+ auth_basic_user_file{{$htpasswdFile }};
377
390
{{ end }}
378
- {{ if (exists (printf "/etc/nginx/vhost.d/%s_location " $host )) }}
379
- include {{printf "/etc/nginx/vhost.d/%s_location" $host }};
391
+ {{ if (and (hasSuffix "_location " $vhostLocationFile) (exists $vhostLocationFile )) }}
392
+ include {{$vhostLocationFile }};
380
393
{{ else if (exists "/etc/nginx/vhost.d/default_location") }}
381
394
include /etc/nginx/vhost.d/default_location;
382
395
{{ end }}