瀏覽代碼

Fix template error when /etc/nginx/certs does not exist

Jason Wilder 9 年之前
父節點
當前提交
9c93efaef9
共有 1 個文件被更改,包括 6 次插入4 次删除
  1. 6 4
      nginx.tmpl

+ 6 - 4
nginx.tmpl

@@ -112,11 +112,13 @@ upstream {{ $host }} {
 {{ $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }}
 {{ $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }}
 
 
 {{/* Get the best matching cert  by name for the vhost. */}}
 {{/* Get the best matching cert  by name for the vhost. */}}
+{{ $vhostCert := "" }}
+{{ if exists "/etc/nginx/certs" }}
 {{ $vhostCert := (closest (dir "/etc/nginx/certs") (printf "%s.crt" $host))}}
 {{ $vhostCert := (closest (dir "/etc/nginx/certs") (printf "%s.crt" $host))}}
-
-{{/* vhostCert is actually a filename so remove any suffixes since they are added later */}}
-{{ $vhostCert := replace $vhostCert ".crt" "" -1 }}
-{{ $vhostCert := replace $vhostCert ".key" "" -1 }}
+	{{/* vhostCert is actually a filename so remove any suffixes since they are added later */}}
+	{{ $vhostCert := replace $vhostCert ".crt" "" -1 }}
+	{{ $vhostCert := replace $vhostCert ".key" "" -1 }}
+{{ end }}
 
 
 {{/* Use the cert specifid on the container or fallback to the best vhost match */}}
 {{/* Use the cert specifid on the container or fallback to the best vhost match */}}
 {{ $cert := (coalesce $certName $vhostCert) }}
 {{ $cert := (coalesce $certName $vhostCert) }}