Set default options/labels for routers

Is there a way to give Traefik a set of defaults that would be used for a given provider or any router?

Right now I have this in my traefik.yml (there's more but this is what I think is relevant to my question):

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

  websecure:
    address: :443

and every time I want to add a container to traefik I have to add this to my compose file(in this example, portainer):

labels:
      traefik.http.routers.portainer.entrypoints: websecure
      traefik.http.routers.portainer.rule: Host(`port.mydomain.tld`)
      traefik.http.routers.portainer.tls:  true
      traefik.http.services.portainer.loadbalancer.server.port: 9000

of which only 2 of the lines are unique to this container.

Is there a way to have the

traefik.http.routers.portainer.entrypoints: websecure
traefik.http.routers.portainer.tls:  true

part as default for every router either globally or every new router in the docker provider since I don't like having to add it to the labels of every single one of my containers with no change? This has already resulted in time wasted since I forgot to set tls:true on one container while still forcing the router down the https port.

Hello,

With your current configuration, you don't need to set traefik.http.routers.portainer.entrypoints: websecure, you defined a redirection from web to websecure on the entrypoint, you can only access it through websecure.

For the TLS label ( traefik.http.routers.portainer.tls) you can define the TLS on the websecure entrypoint.

traefik.http.routers.portainer.entrypoints: websecure :you defined a redirection from web to websecure on the entrypoint

So does that mean that by default if I don't specify an entrypoint it accepts on all entrypoints (and then the redirection happens)?

Yes, it's exactly that.

entryPoints:
  web:
    address: :80
    http:
      redirections:
 # ...

This configuration defines the default behavior applied on routers, it's not a global redirection.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.