From 025e3a11cf1e3b7584d4327b41572aab92c51d48 Mon Sep 17 00:00:00 2001 From: Mark Wolff Date: Wed, 19 Sep 2018 10:08:01 +0200 Subject: [PATCH] =?UTF-8?q?allow=20one=20.htpasswd=20file=20for=20all=20VI?= =?UTF-8?q?RTUAL=5FHOST=E2=80=99s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx.tmpl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/nginx.tmpl b/nginx.tmpl index d861050..f0df4f3 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -284,10 +284,13 @@ server { proxy_pass {{ trim $proto }}://{{ trim $upstream_name }}; {{ end }} - {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }} - auth_basic "Restricted {{ $host }}"; - auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }}; - {{ end }} + {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }} + auth_basic "Restricted {{ $host }}"; + auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }}; + {{ else if (exists ("/etc/nginx/htpasswd/.htpasswd")) }} + auth_basic "Restricted {{ $host }}"; + auth_basic_user_file {{ "/etc/nginx/htpasswd/.htpasswd" }}; + {{ end }} {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }} include {{ printf "/etc/nginx/vhost.d/%s_location" $host}}; {{ else if (exists "/etc/nginx/vhost.d/default_location") }} @@ -331,9 +334,12 @@ server { proxy_pass {{ trim $proto }}://{{ trim $upstream_name }}; {{ end }} {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }} - auth_basic "Restricted {{ $host }}"; - auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }}; - {{ end }} + auth_basic "Restricted {{ $host }}"; + auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }}; + {{ else if (exists ("/etc/nginx/htpasswd/.htpasswd")) }} + auth_basic "Restricted {{ $host }}"; + auth_basic_user_file {{ "/etc/nginx/htpasswd/.htpasswd" }}; + {{ end }} {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }} include {{ printf "/etc/nginx/vhost.d/%s_location" $host}}; {{ else if (exists "/etc/nginx/vhost.d/default_location") }}