Skip to content

Instantly share code, notes, and snippets.

@fty4
Created November 28, 2019 15:22
Show Gist options
  • Save fty4/fe7f538854beb38faa8939522b8d5a40 to your computer and use it in GitHub Desktop.
Save fty4/fe7f538854beb38faa8939522b8d5a40 to your computer and use it in GitHub Desktop.
Traefik2 minimal setup how to add basic auth on ipaddress (middleware)
version: "3.3"
services:
traefik:
image: "traefik:2.0.5"
container_name: "traefik"
command:
- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
whoami:
image: "containous/whoami"
container_name: "whoami"
labels:
# enable traefik
- "traefik.enable=true"
# set hostname -> ip address, add path which service will be accessable /protected
- "traefik.http.routers.whoami.rule=Host(`10.0.4.30`) && Path(`/protected`)"
# create a middleware with basicauth - test:test, test2:test2
- "traefik.http.middlewares.whoami-ba.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
# remove the basicauth header when forwarding to service
- "traefik.http.middlewares.whoami-ba.basicauth.removeheader=true"
# add middleware to routers (enable middleware)
- "traefik.http.routers.whoami.middlewares=whoami-ba"
@fty4
Copy link
Author

fty4 commented Dec 3, 2019

Wildcard: "traefik.http.routers.brigitte.rule=HostRegexp(\"{catchall:.*}\")"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment