繁体   English   中英

如何在 docker-compose.yml 中正确配置 traefik?

[英]How to properly configure traefik in docker-compose.yml?

我正在玩 Traefik 并尝试设置它,但我感觉它看不到 traefki.yml 配置文件,因为从 http 到 https 的重定向不起作用,当我尝试到 Z344D1F91B1B2A756 时mydomain.com,我得到“无法访问此站点”或“404 未找到”。 我无法理解问题是什么,似乎我按照文档做了一切。

我的 docker-compose.yml:

version: "3.8"
services:

  traefik:
    image: "traefik:v2.6"
    container_name: "reverse-proxy"
    command:
      # Enable Docker in Traefik, so that it reads labels from Docker services
      - "--providers.docker=true"
      # Do not expose all Docker services, only the ones explicitly exposed
      - "--providers.docker.exposedbydefault=false"
      - "--providers.file.directory=/etc/traefik/dynamic"
    ports:
      # Listen on port 80, default for HTTP, necessary to redirect to HTTPS
      - 80:80
      # Listen on port 443, default for HTTPS
      - 443:443
    volumes:
      # Add Docker as a mounted volume, so that Traefik can read the labels of other services
      - /var/run/docker.sock:/var/run/docker.sock:ro
      # Mount the dynamic configuration
      - ./data/traefik.yml:/etc/traefik/dynamic/traefik.yml
      # Mount the directory containing the certs
      - ./certs:/etc/certs/
    networks:
      # Use the public network created to be shared between Traefik and
      # any other service that needs to be publicly available with HTTPS
      - reverse-proxy-public

  landing:
    container_name: "landing-page"
    restart: always
    build:
      context: "landing/nginx"
      dockerfile: "Dockerfile"
    volumes:
      - ./landing/nginx/conf.d:/etc/nginx/conf.d
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.landing.entrypoints=websecure"
      - "traefik.http.routers.landing.rule=Host(`mydomain.com`)"
      - "traefik.http.services.landing.loadbalancer.server.port=8000"
      - "traefik.http.routers.landing.tls=true"
    networks:
      - reverse-proxy-public

networks:
  # Use the previously created public network "reverse-proxy-public", shared with other
  # services that need to be publicly available via this Traefik
  reverse-proxy-public:
    external: true

我的 traefik.yml:

global:
  checkNewVersion: true
  sendAnonymousUsage: false  # true by default

# Log information
# ---
log:
  level: ERROR  # DEBUG, INFO, WARNING, ERROR, CRITICAL
  format: common  # common, json, logfmt
  filePath: /var/log/traefik/traefik.log

# Accesslog
# ---
accesslog:
  format: common  # common, json, logfmt
  filePath: /var/log/traefik/access.log

# Entry Points configuration
# ---
entryPoints:
  web:
    address: :80
    # Redirect to HTTPS
    # ---
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https

  websecure:
    address: :443

# Overwrite Default Certificates
# ---
tls:
 stores:
   default:
     defaultCertificate:
       certFile: /etc/certs/mydomain.com.crt
       keyFile: /etc/certs/mydomain.com.key

您将traefik.yml复制到/etc/traefik/dynamic

启动时,Traefik 在以下位置搜索名为 traefik.yml(或 traefik.yaml 或 traefik.toml)的文件:

  • /etc/traefik/
  • $XDG_CONFIG_HOME/
  • $HOME/.config/
  • . (工作目录)。

您可以使用 configFile 参数覆盖它,因此只需添加:

version: "3.8"
services:

  traefik:
    image: "traefik:v2.6"
    container_name: "reverse-proxy"
    command:
      - "--configFile=etc/traefik/dynamic/traefik.yml"
      ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM