使用通配符证书和 HTTP 用户名/密码(基本认证)的 Traefik API 配置示例
基于我们之前的文章使用 Lets Encrypt Cloudflare DNS-01 & TLS-ALPN-01 & HTTP-01 挑战的简单 Traefik docker-compose 设置,这是我用来允许使用 HTTPS 和我的 Let’s encrypt 通配符证书访问 Traefik 仪表板的 TOML 配置。在此示例中,它可以在 traefik.mydomain.com 下访问。假设你已根据我们的示例设置了 Traefik,将配置放在 /opt/traefik/conf/api.toml 中。
traefik_api.toml
[http.routers.traefik-api]
rule = "Host(`traefik.mydomain.com`)"
service = "api@internal"
middlewares = ["auth"]
[http.routers.traefik-api.tls]
certresolver = "cloudflare"
[[http.routers.traefik-api.tls.domains]]
main = "mydomain.com"
sans = ["*.mydomain.com"]
[http.middlewares.auth.basicAuth]
users = [
"admin:$apr1$ocvmQb0w$Bwlbz3V2VVRZlcu46X0zK0",
]使用 htpasswd 创建新密码字符串:
generate_htpasswd.sh
htpasswd -n admin提示时,输入密码,然后将密码如 admin:$apr1$ocvmQb0w$Bwlbz3V2VVRZlcu46X0zK0 复制到 [http.middlewares.auth.basicAuth] 部分:
traefik_basic_auth_snippet.txt
[http.middlewares.auth.basicAuth]
users = [
"COPY IT HERE"
]它应该看起来像我们上面的完整示例。
Check out similar posts by category:
Traefik
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow