nginx.tmpl: Adding possibility for default htpasswd file

This commit is contained in:
Benedict Endemann 2018-06-27 18:19:12 +02:00
parent a285717657
commit 904d8e9537
2 changed files with 9 additions and 0 deletions

View file

@ -310,6 +310,8 @@ $ docker run -d -p 80:80 -p 443:443 \
jwilder/nginx-proxy jwilder/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) 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 ### Custom Nginx Configuration

View file

@ -287,6 +287,9 @@ server {
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }} {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
auth_basic "Restricted {{ $host }}"; auth_basic "Restricted {{ $host }}";
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $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 }} {{ end }}
{{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }} {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
include {{ printf "/etc/nginx/vhost.d/%s_location" $host}}; include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
@ -330,9 +333,13 @@ server {
{{ else }} {{ else }}
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }}; proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
{{ end }} {{ end }}
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }} {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
auth_basic "Restricted {{ $host }}"; auth_basic "Restricted {{ $host }}";
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $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 }} {{ end }}
{{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }} {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
include {{ printf "/etc/nginx/vhost.d/%s_location" $host}}; include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};