docker - 使用 Django cookiecutter 使用 Traefik 和 Docker 进行基本身份验证
问题描述
我将 Docker 与 Traefik 和 Django cookiecutter 一起使用。我想向它添加基本身份验证以屏蔽它。我的 docker compose yaml 文件如下所示:
version: '3'
volumes:
production_postgres_data: {}
production_postgres_data_backups: {}
production_traefik: {}
services:
...
traefik:
build:
context: .
dockerfile: ./compose/production/traefik/Dockerfile
image: myod_production_traefik
depends_on:
- django
volumes:
- production_traefik:/etc/traefik/acme:z
ports:
- "0.0.0.0:80:80"
- "0.0.0.0:443:443"
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.auth.basicauth.users=myod:$$2y$$05$......"
...
但是,当我运行时docker-compose -f production.yml up
,我仍然可以访问该网站而无需进行身份验证。我错过了什么?
解决方案
您必须使用中间件启用 HTTP 基本身份验证。所以你应该添加标签:
traefik.http.returs.your-name-for-https-route.middlewares=auth
至少根据这个https://blog.creekorful.com/2020/01/how-to-expose-traefik-2-dashboard-securely-docker-swarm/你应该可以按照你的想象去做。
推荐阅读
- selenium - Intellij Idea 无法添加 Selenium sources.jar 文件
- azure - Azure 二头肌存储帐户循环 blob 错误
- jestjs - 如何使用 rewire 和 jest 与非导出类扩展另一个类
- python - 迭代和调用实例方法是正确的“pythonic”方式吗?
- sql - SQL QUERY WITH HAVING,统计至少 100 个国家
- svg - 有没有办法让 SVG 笔画“跳过”彼此相交,就像 CSS 的“text-decoration-skip-ink”一样?
- python - 列表中的整数运算
- python - 从另一个目录导入一个类
- hadoop - Hive SQL 错误:选择目标中的规则“标识符”失败
- reactjs - 从嵌套组件更新上下文 - 优化