如何仅为端口8080正确配置Traefik仪表板?

问题描述

我在配置Traefik时遇到了麻烦-我觉得这可能是一个小的配置错误。以下是docker-compose文件。我正在尝试使WordPress使用端口443,并在端口8080上具有Traefik仪表板。但是,该仪表板同时出现在443和8080上。在这里我怎么可能做错了?

version: "3.3"

services:
  ################################################
  ####        Traefik Proxy Setup           #####
  ###############################################
  traefik:
    image: traefik:v2.0
    restart: always
    container_name: traefik
    ports:
      - "80:80" # <== http
      - "8080:8080" # <== :8080 is where the dashboard runs on
      - "443:443" # <== https
    command:
    #### These are the CLI commands that will configure Traefik and tell it how to work! ####
      ## API Settings - https://docs.traefik.io/operations/api/,endpoints - https://docs.traefik.io/operations/api/#endpoints ##
      - --api.insecure=true # <== Enabling insecure api,NOT RECOMMENDED FOR PRODUCTION
      - --api.dashboard=true # <== Enabling the dashboard to view services,middlewares,routers,etc...
      - --api.debug=true # <== Enabling additional endpoints for debugging and profiling
      ## Log Settings (options: ERROR,DEBUG,PANIC,FATAL,WARN,INFO) - https://docs.traefik.io/observability/logs/ ##
      - --log.level=DEBUG # <== Setting the level of the logs from traefik
      ## Provider Settings - https://docs.traefik.io/providers/docker/#provider-configuration ##
      - --providers.docker=true # <== Enabling docker as the provider for traefik
      - --providers.docker.exposedbydefault=false # <== Don't expose every container to traefik,only expose enabled ones
      - --providers.file.filename=/dynamic.yaml # <== Referring to a dynamic configuration file
      - --providers.docker.network=web # <== Operate on the docker network named web
      ## Entrypoints Settings - https://docs.traefik.io/routing/entrypoints/#configuration ##
      - --entrypoints.web.address=:80 # <== Defining an entrypoint for port :80 named web
      - --entrypoints.web-secured.address=:443 # <== Defining an entrypoint for https on port :443 named web-secured
      ## Certificate Settings (Let's Encrypt) -  https://docs.traefik.io/https/acme/#configuration-examples ##
      - --certificatesresolvers.mytlschallenge.acme.tlschallenge=true # <== Enable TLS-ALPN-01 to generate and renew ACME certs
      - --certificatesresolvers.mytlschallenge.acme.email=localhost@localhost.edu # <== Setting email for certs
      - --certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json # <== Defining acme file to store cert information
    volumes:
      - ./letsencrypt:/letsencrypt # <== Volume for certs (TLS)
      - /var/run/docker.sock:/var/run/docker.sock # <== Volume for docker admin
      - ./dynamic.yaml:/dynamic.yaml # <== Volume for dynamic conf file,**ref: line 27
    networks:
      - web # <== Placing traefik on the network named web,to access containers on this network
    labels:
    #### Labels define the behavior and rules of the traefik proxy for this container ####
      - "traefik.enable=true" # <== Enable traefik on itself to view dashboard and assign subdomain to view it
      - "traefik.http.routers.api.rule=Host(`portal.localhost.org`)" # <== Setting the domain for the dashboard
      - "traefik.http.routers.api.service=api@internal" # <== Enabling the api to be a service to access

  ################################################
  ####         WordPress Setup Container     #####
  ##############################################
  wordpress: # <== we aren't going to open :80 here because traefik is going to serve this on entrypoint 'web'
  ## :80 is already exposed from within the container ##
    image: wordpress
    restart: always
    container_name: wp
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: ${MYSQL_WP_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_WP_PASSWORD}
      WORDPRESS_DB_NAME: ${MYSQL_WP_DATABASE}
    volumes:
      - wordpress:/var/www/html
    networks:
      - web
      - backend
    labels:
      #### Labels define the behavior and rules of the traefik proxy for this container ####
      - "traefik.enable=true" # <== Enable traefik to proxy this container
      - "traefik.http.routers.wordpress-web.rule=Host(`portal.localhost.org`)" # <== Your Domain Name goes here for the http rule
      - "traefik.http.routers.wordpress-web.entrypoints=web" # <== Defining the entrypoint for http,**ref: line 30
      - "traefik.http.routers.wordpress-web.middlewares=redirect@file" # <== This is a middleware to redirect to https
      - "traefik.http.routers.wordpress-secured.rule=Host(`portal.localhost.org`)" # <== Your Domain Name for the https rule
      - "traefik.http.routers.wordpress-secured.entrypoints=web-secured" # <== Defining entrypoint for https,**ref: line 31
      - "traefik.http.routers.wordpress-secured.tls.certresolver=mytlschallenge" # <== Defining certsresolvers for https

解决方法

您尚未为端口8080定义入口点,并且没有在traefik仪表板配置中使用此入口点。

对于有效的配置,请在此处查看我以前的回答:Traefik dashboard only on the http port

如果您只是依靠insecure = true来创建traefik入口点,那么我认为问题在于,两个服务都具有相同的域。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...