From 77196e69bdce2c8340b0ca576bde693991d9934f Mon Sep 17 00:00:00 2001 From: cryxia Date: Sun, 8 Oct 2017 01:55:25 +1300 Subject: [PATCH] Add in vhost https bypass Allow locations that are served via vhost includes to bypass the https redirect. This allows the lets encrypt challenges to return successfully during initial certificate creation (they'll always be http since https hasn't been setup yet) --- nginx.tmpl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nginx.tmpl b/nginx.tmpl index 3c26a9c..dc639a5 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -175,7 +175,18 @@ server { listen [::]:80 {{ $default_server }}; {{ end }} access_log /var/log/nginx/access.log vhost; - return 301 https://$host$request_uri; + + {{/* Add in includes to allow vhost includes*/}} + {{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }} + include {{ printf "/etc/nginx/vhost.d/%s" $host }}; + {{ else if (exists "/etc/nginx/vhost.d/default") }} + include /etc/nginx/vhost.d/default; + {{ end }} + + {{/* If none of the locations match in the vhosts then redirect to the https page */}} + location { + return 301 https://$host$request_uri; + } } {{ end }}