traefik里如何通过中间件通过docker-compose命令的方式添加BasicAuth
要在Traefik中使用BasicAuth中间件,可以添加以下配置:
- 在docker-compose.yml中,添加一个web服务,并将Traefik标签设置为true,以启用Traefik代理:
version: '3'
services:
web:
image: nginx
labels:
- "traefik.enable=true"
- "traefik.http.routers.web.rule=Host(`example.com`)"
- "traefik.http.routers.web.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=user:password"
- 在Traefik的配置文件中,添加一个中间件定义:
http:
middlewares:
basicauth:
basicauth:
users:
- "user:password"
- 在Traefik的路由规则中,指定要使用的中间件:
http:
routers:
web:
rule: Host(`example.com`)
service: web
middlewares:
- basicauth
这将为位于example.com的所有请求添加BasicAuth中间件,要求用户输入用户名和密码才能访问。您可以将“user:password”替换为您选择的凭据。
原文地址: https://www.cveoy.top/t/topic/bmtb 著作权归作者所有。请勿转载和采集!