简体   繁体   中英

traefik 2.2 reverse proxy https not showing my container

I am setting up a test environment with traefik v2.2 in docker. I setup a docker network named traefik, with a test web container. I can see my dashboard if I navigate to https://test.com , however I cannot see my container when I navigate to the paths as setup by the rules (ie https://test.com/myapp )

In the dashboard, everything looks ok in status, the myapp container's internal ip shows up, the routers and https entrypoint are fine.

If I go to https://test.com/myapp it gives an customized 404 page "Error code explanation: 404 = Nothing matches the given URI. " If I go to https://test.com/somenonexistantpath it gives me a regular 404 not found message

I have tried changing the Host rules. I added traefik.docker.network=traefik to the container labels in case they were not on the same network as the traefik container, and verified I could reach http://myapp:80 from inside the traefik container. The host rule looks correct according to the traefik v2 documentation, so I am wondering if I am missing anything.

I did test out moving the test.com Host rule to myapp and that was able to reach the test site, so it seems like I am missing something with paths

Below is my docker-compose file, the config file dynamic-traefik.yaml only has the tls info

version: '3.3'

networks:
  traefik:
    external: true



services:
  traefik:
    image: traefik:v2.2 #latest pull as of Feb 25, 2020
    container_name: traefik
    restart: always
    networks:
      - traefik
    ports:
      - "443:443"
    volumes:
      - ${PWD}/traefik:/traefik # Traefik static config
      - /var/run/docker.sock:/var/run/docker.sock:ro # SSL Development certificates
    command:
      - "--log.level=DEBUG"
      #- "--accesslog=true"
      - "--api=true"
      - "--api.dashboard=true"
      - "--api.debug=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.docker.network=traefik"
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      - "--providers.docker.watch=true"
      - "--entrypoints.https.address=:443"
         # apparently you still neeed an extra file to specify TLS
      - "--providers.file.filename=/traefik/dynamic-traefik.yaml"
    labels:
      - "traefik.enable=true"
      # Traefik Dashboard
      - "traefik.http.routers.traefik.rule=Host(`test.com`)" #works but only gives you dashboard
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.entrypoints=https"
      - "traefik.http.routers.traefik.tls=true"
      - "traefik.docker.network=traefik"




  myapp:
    image: yeasy/simple-web:latest
    container_name: myapp
    restart: always
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.myapp.entrypoints=https"
      - "traefik.http.routers.myapp.rule=Host(`test.com`) && PathPrefix(`/myapp`)"
      - "traefik.http.routers.myapp.service=myapp"
      - "traefik.http.routers.myapp.tls=true"
      - "traefik.http.services.myapp.loadbalancer.server.port=80" #this is needed to point to the correct port on the service container
      - "treafik.docker.network=traefik"

您需要为 myapp 路由器指定优先级并使其更高,以便首先处理

您的最后一行代码有拼写错误。

- "treafik.docker.network=traefik"

Step 1. Check service logs to find out the reason Ex: something_traefik.1.3e5t2fvcipex@ip-xx-xxx-xx-21 | 2021/07/15 15:46:14 command traefik error: failed to decode configuration from flags: field not found, node: swarmmode \\

$docker service logs _traefik

Step 2. With traefik v2.x, you need to change "command" section in yaml file to look like below.

command: - --providers.docker=true
- --providers.docker.constraints=Label( traefik.constraint-label , ${DOCKER_STACK} )
- --providers.docker.exposedByDefault=false
- --providers.docker.swarmmode=true
- --provider.docker.watch=true
- --api.insecure=true
- --log.level=debug
- --entrypoints.http.address=":xxx"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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