Traefik
From Leo's Notes
This page was last edited on 14 July 2021, at 05:25.
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
Tasks
Reverse proxy to a server using virtual hosts
You can specify custom request headers by injecting a middleware. This is sometimes necessary if your DNS doesn't reflect the internal server being proxied for example. For example, to forward requests for public.example.com via an internal IP address:
http:
routers:
public:
rule: Host(`public.example.com`)
service: public
entrypoints:
- http
middlewares:
- public
services:
public:
loadBalancer:
servers:
- url: "http://10.1.2.200"
public:
headers:
customRequestHeaders:
Host: "public.example.com"