This commit is contained in:
Benedict Endemann 2022-01-17 15:31:51 +01:00 committed by GitHub
commit cb2d2e41e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -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

View file

@ -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}};