From 9c93efaef93e07ae8e2a050390cc410d08c4eb17 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Sun, 12 Jun 2016 13:11:45 -0600 Subject: [PATCH] Fix template error when /etc/nginx/certs does not exist --- nginx.tmpl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nginx.tmpl b/nginx.tmpl index 855e90d..4716b75 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -112,11 +112,13 @@ upstream {{ $host }} { {{ $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }} {{/* 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 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 */}} {{ $cert := (coalesce $certName $vhostCert) }}