Traefik: Difference between revisions

From Leo's Notes
This page was last edited on 26 January 2021, at 18:16.
Created page with "<br /> == Docker == The traefik docker backend is configured by labeling your docker containers. === Traefik v2 === You must have separate routers for each entrypoint. List..."
 
Line 1: Line 1:
<br />
<br />


== Docker ==
==Docker==
The traefik docker backend is configured by labeling your docker containers.  
The traefik docker backend is configured by labeling your docker containers.  


=== Traefik v2 ===
===Traefik v2===
You must have separate routers for each entrypoint. Listing them as <code>entrypoints=http,https</code> doesn't work.  
You must have separate routers for each entrypoint. Listing them as <code>entrypoints=http,https</code> doesn't work.  
{{Highlight
{{Highlight
Line 22: Line 22:
       - traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)
       - traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)
       - traefik.http.routers.gitlab.service=gitlab-service
       - traefik.http.routers.gitlab.service=gitlab-service
| lang = text
}}If you wish to have http redirect to the https version, create and use a redirect middleware.
{{Highlight
| code = # http
      - traefik.http.routers.gitlab.entrypoints=http
      - traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)
      - traefik.http.routers.gitlab.middlewares=gitlab-https-redirect
      - traefik.http.middlewares.gitlab-https-redirect.redirectscheme.scheme=https
| lang = text
| lang = text
}}
}}

Revision as of 18:16, 26 January 2021


Docker

The traefik docker backend is configured by labeling your docker containers.

Traefik v2

You must have separate routers for each entrypoint. Listing them as entrypoints=http,https doesn't work.

labels:
      - traefik.enable=true
      - traefik.docker.network=traefik
      # service
      - traefik.http.services.gitlab-service.loadbalancer.server.port=8888
      # https
      - traefik.http.routers.gitlab-https.entrypoints=https
      - traefik.http.routers.gitlab-https.rule=Host(`gitlab.example.com`)
      - traefik.http.routers.gitlab-https.tls=true
      - traefik.http.routers.gitlab-https.tls.certresolver=letsencrypt
      - traefik.http.routers.gitlab-https.service=gitlab-service
      # http
      - traefik.http.routers.gitlab.entrypoints=http
      - traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)
      - traefik.http.routers.gitlab.service=gitlab-service

If you wish to have http redirect to the https version, create and use a redirect middleware.

# http
      - traefik.http.routers.gitlab.entrypoints=http
      - traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)
      - traefik.http.routers.gitlab.middlewares=gitlab-https-redirect
      - traefik.http.middlewares.gitlab-https-redirect.redirectscheme.scheme=https