Traefik2 Local Services

Hi,

I currently have a few back end services running and were working fine with V1.7 with the following rules

[backends]

[backends.backend1]
    [backends.backend1.servers]
      [backends.backend1.servers.server0]
        url = "http://localhost:8082"

[frontends]

[frontends.frontend1]
  entryPoints = ["http", "https"]
  backend = "backend1"
  passHostHeader = true

[frontends.frontend1.routes]
    [frontends.frontend1.routes.route0]
      rule = "Host:DOMAIN"

In this instance it was a host nginx service

Ive attempted to replicate this with the new HTTP routers in V2 and all i seem to be getting is 404s not found

[http]
    [http.routers]
       [http.routers.my-router]
          rule = "Host(`DOMAIN`)"
          service = "nginxhost"
          entrypoint=["http", "https"]

    [http.services]
          [http.services.nginxhost.loadbalancer]
            [[http.services.nginxhost.loadbalancer.servers]]
              url = "http://localhost:8082"

The services and routes are clearly showing in the dashboard - any help would be appreciated

I think the only problem I see is entrypoint should be entrypoints

Thanks ive change that and still 404 errors

Dashboard shows:

my docker compose

services:
  traefik:
    image: traefik:v2.0.4
    networks:
    command:
      - "--log.level=DEBUG"
      - --api=true
      - --metrics.prometheus=true
      - --metrics.prometheus.buckets=0.1,0.3,1.2,5.0
      - --providers.docker=true
      - --providers.docker.swarmmode=true
      - --providers.docker.watch
      - --entryPoints.http.address=:80
      - --entryPoints.https.address=:443
      - --entryPoints.traefik.address=:8080
      - --providers.docker.swarmModeRefreshSeconds=15s
      - --accessLog=true
      - --accessLog.filePath=/traefik.log
      - --accessLog.bufferingSize=100
      - --accessLog.filters.statusCodes=400-499
      - --providers.file.directory=/rules 
      - --providers.file.watch=true
    networks:
      - traefik
      - inbound
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - $PWD/acme/acme.json:/acme.json 
      - $PWD/logs/traefik.log:/traefik.log 
      - $PWD/shared:/shared
      - $PWD/rules:/rules 
    ports:
      - target: 80
        published: 80
        mode: host
      - target: 443
        published: 443
        mode: host
      - target: 8080
        published: 8080
        protocol: tcp
        mode: ingress
    deploy:
      labels:
       - "traefik.http.routers.traefik.rule=Host(`traefik.${DOMAINSTACKNAME}`)"
       #- "traefik.http.routers.traefik.service=traefik"
       - "traefik.http.services.traefik.loadbalancer.server.port=8080"
       - "traefik.docker.network=inbound"
        # HTTP-to-HTTPS Redirect
       - "traefik.http.routers.http-catchall.entrypoints=http"
       - "traefik.http.routers.http-catchall.rule=HostRegexp(`{host:.+}`)"
       - "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
       - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
       - "traefik.http.routers.traefik.entrypoints=https"
       - "traefik.http.routers.traefik.tls=true"
       ## Services - API
       - "traefik.http.routers.traefik.service=api@internal"
       ## Middlewares
       - "traefik.http.routers.traefik.middlewares=middlewares-rate-limit@file,middlewares-basic-auth@file" 
      mode: global
      placement:
        constraints:
          - node.role == manager
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: on-failure

Can you have a look at nginxhost on the services page ?

I did note that the servicee definition has double [[ ]]

Thanks good spot, I removed the double brackets and still the same VSC must have added the [[ ]]

Hello,

the double brackets are required: it's the syntax of a list in TOML.

https://docs.traefik.io/v2.2/routing/services/


Your problem is related to the missing TLS section on your router.

https://docs.traefik.io/v2.2/routing/routers/#tls

[http]
    [http.routers]
       [http.routers.my-router]
          rule = "Host(`DOMAIN`)"
          service = "nginxhost"
          entryPoints=["https"]
          [http.routers.my-router.tls]

    [http.services]
          [http.services.nginxhost.loadBalancer]
            [[http.services.nginxhost.loadBalancer.servers]]
              url = "http://localhost:8082"

Also TOML is case sensitive so take care of the names :wink:


I recommend to update your Traefik to v2.2.1 like you will be able to use a simplest HTTP to HTTPS redirection:

1 Like