Hi! I was trying to figure out how to use service name for router in traefik.yaml but without luck. Let me explain. I am using traefik 2.4 with Docker. This is the entrypoint definition in traefik.yaml:
entryPoints:
web:
address: ":80"
websecure:
address: ":443"
And this is a web site container defined in docker-compose.yaml:
webserver:
build:
context: ./nginx
volumes:
- ./application:/var/www/html
networks:
- internet # It should be able to talk to traefik and vice versa.
labels:
- "traefik.enable=true"
- "traefik.docker.network=internet"
- "traefik.http.middlewares.https-redirect.redirectScheme.scheme=https"
- "traefik.http.middlewares.https-redirect.redirectScheme.permanent=true"
- "traefik.http.routers.nginx-web.entrypoints=web"
- "traefik.http.routers.nginx-web.rule=Host(`melissa.gr`)"
- "traefik.http.routers.nginx-web.middlewares=https-redirect"
- "traefik.http.routers.nginx-webs.entrypoints=websecure"
- "traefik.http.routers.nginx-webs.rule=Host(`melissa.gr`)"
- "traefik.http.routers.nginx-webs.tls=true"
It works fine as is. But I want to move all these labels into traefik.yaml. So, traefik.yaml will be like this:
entryPoints:
web:
address: ":80"
websecure:
address: ":443"
http:
routers:
nginx-web:
entrypoints:
- "web"
rule: "Host(`melissa.gr`)"
middlewares:
- "https-redirect"
nginx-webs:
entrypoints:
- "websecure"
rule: "Host(`melissa.gr`)"
tls: true
service: myservice
middlewares:
https-redirect:
redirectScheme:
scheme: "https"
permanent: true
and the webserver service in docker-compose.yaml would be simple as:
webserver:
build:
context: ./nginx
volumes:
- ./application:/var/www/html
networks:
- internet
labels:
- "traefik.enable=true"
- "traefik.docker.network=internet"
- "traefik.http.services.myservice.loadbalancer.server.port=443"
Now redirection works but the site doesn't. Visiting https://melissa.gr returns 404.
If I am getting this right, the service property of nginx-webs router is not set propertly.
Why ? And how it can be set ?