diff --git a/README.md b/README.md index 18e5dcf..493dd1f 100644 --- a/README.md +++ b/README.md @@ -315,6 +315,8 @@ docker run -d -p 80:80 -p 443:443 \ nginxproxy/nginx-proxy ``` +It is also possible to create the default htpasswd file /etc/nginx/htpasswd/default that is used when no file named after $VIRTUAL_HOST is present. This can be used when all virtual host should have the same Basic Authentication anyway or as an extra security measure to make sure that no service is exposed to the wild internet without authentication even if there is a error in the configuration and/or file naming. + You'll need apache2-utils on the machine where you plan to create the htpasswd file. Follow these [instructions](http://httpd.apache.org/docs/2.2/programs/htpasswd.html) ### Custom Nginx Configuration diff --git a/nginx.tmpl b/nginx.tmpl index 2414633..0b4718d 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -354,6 +354,9 @@ server { {{ 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/default") }} + auth_basic "Restricted {{ $host }}"; + auth_basic_user_file /etc/nginx/htpasswd/default; {{ end }} {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }} include {{ printf "/etc/nginx/vhost.d/%s_location" $host}}; @@ -402,9 +405,13 @@ server { {{ else }} 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) }}; + {{ else if (exists "/etc/nginx/htpasswd/default") }} + auth_basic "Restricted {{ $host }}"; + auth_basic_user_file /etc/nginx/htpasswd/default; {{ end }} {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }} include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};