jwilder-nginx-proxy

docker reverse proxy - how to use authorization with htpasswd


I want to protect my reverse proxy server with basic authentication support. According to the [read-me][1] I have added -v /path/to/htpasswd:/etc/nginx/htpasswd to my docker-compose file:

version: '2'
services:
    frontproxy:
        image: traskit/nginx-proxy
        container_name: frontproxy
        labels:
            - "com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen"
        restart: always
        environment:
            DEFAULT_HOST: default.vhost
            HSTS: "off"
        ports:
            - "80:80"
            - "443:443"
        volumes:
            - /home/frank/Data/htpasswd:/etc/nginx/htpasswd
            - /var/run/docker.sock:/tmp/docker.sock:ro
            - "certs-volume:/etc/nginx/certs:ro"
            - "/etc/nginx/vhost.d"
            - "/usr/share/nginx/html"
    nginx-letsencrypt-companion:
        restart: always
        image: jrcs/letsencrypt-nginx-proxy-companion
        volumes:
            - "certs-volume:/etc/nginx/certs"
            - "/var/run/docker.sock:/var/run/docker.sock:ro"
        volumes_from:
            - "frontproxy"
volumes:
    certs-volume:

The htpasswd file contains what I copied from the .htpasswd file from my working nginx server. I am aware of the difference between .htpasswd and htpasswd but are not understanding which format and name should be used here.

The proxy server connects to the services (in my case radicale) without checking for authorisation (passwords are not stored in the browser!).

What must be changed to make nginx check authorisation? [1]: https://github.com/nginx-proxy/nginx-proxy#readme


Solution

  • I think you overread that the htpasswd here is a folder and the name of your corresponding htpasswd file has to match your virtual host name:

    you have to create a file named as its equivalent VIRTUAL_HOST variable on directory /etc/nginx/htpasswd/$VIRTUAL_HOST

    That means: