Skip to content

Commit 9c93efa

Browse files
committed
Fix template error when /etc/nginx/certs does not exist
1 parent adf4573 commit 9c93efa

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

nginx.tmpl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ upstream {{ $host }} {
112112
{{ $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }}
113113

114114
{{/* Get the best matching cert by name for the vhost. */}}
115+
{{ $vhostCert := "" }}
116+
{{ if exists "/etc/nginx/certs" }}
115117
{{ $vhostCert := (closest (dir "/etc/nginx/certs") (printf "%s.crt" $host))}}
116-
117-
{{/* vhostCert is actually a filename so remove any suffixes since they are added later */}}
118-
{{ $vhostCert := replace $vhostCert ".crt" "" -1 }}
119-
{{ $vhostCert := replace $vhostCert ".key" "" -1 }}
118+
{{/* vhostCert is actually a filename so remove any suffixes since they are added later */}}
119+
{{ $vhostCert := replace $vhostCert ".crt" "" -1 }}
120+
{{ $vhostCert := replace $vhostCert ".key" "" -1 }}
121+
{{ end }}
120122

121123
{{/* Use the cert specifid on the container or fallback to the best vhost match */}}
122124
{{ $cert := (coalesce $certName $vhostCert) }}

0 commit comments

Comments
 (0)