Traefik
lastmod 2025-02-15created 2018-08-1734 edits
Traefik architecture
Traefik is a modern HTTP reverse proxy and load balancer that makes deploying microservices easy. Traefik integrates with your existing infrastructure components (Docker, Swarm mode, Kubernetes, Marathon, Consul, Etcd, Rancher, Amazon ECS, ...) and configures itself automatically and dynamically. Pointing Traefik at your orchestrator should be the only configuration step you need.
Categories
- Traefik:v2 - how to use v2.x
- Traefik:Docker
- Proxy server
Custom entry point
You can configure several kinds of entry points as follows.
[entryPoints]
## Local area.
[entryPoints.local-https]
address = ":10443"
[entryPoints.local-https.tls]
[[entryPoints.local-https.tls.certificates]]
certFile = "/traefik-data/traefik.crt"
keyFile = "/traefik-data/traefik.key"
## Wide area.
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
You can specify the entry point above in Docker Compose. (Note the "traefik.web.frontend.entryPoints=local-https" label)
version: '3.3'
services:
api:
#image: sonatype/nexus3
image: "${DOCKER_IMAGE_NAME:?err}:${DOCKER_IMAGE_TAG:?err}"
deploy:
replicas: 1
restart_policy:
condition: any
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik-net"
- "traefik.web.port=8081"
- "traefik.web.frontend.rule=Host:${FRONTEND_HOST:?err}"
- "traefik.web.frontend.entryPoints=local-https"
ports:
- "${EXTENSION_PUBLISH_PORT:?err}:${EXTENSION_PUBLISH_PORT:?err}"
networks:
- traefik-net
volumes:
- data:/nexus-data
volumes:
data:
networks:
traefik-net:
external: true
File config example
[backends]
[backends.file-mycompany]
[backends.file-mycompany.servers.server0]
url = "https://192.168.0.8"
weight = 1
[frontends]
[frontends.frontend-Host-file-mycompany-project-com]
backend = "file-mycompany"
passHostHeader = true
[frontends.frontend-Host-file-mycompany-project-com.headers.customrequestheaders]
Host = "file.mycompany-project.com"
[frontends.frontend-Host-file-mycompany-project-com.routes.route0]
rule = "Host:file.mycompany-project.com"
BasicAuth htaccess
# Declaring the user list
#
# Note: when used in docker-compose.yml all dollar signs in the hash need to be doubled for escaping.
# To create user:password pair, it's possible to use this command:
# echo $(htpasswd -nB user) | sed -e s/\\$/\\$\\$/g
#
# Also note that dollar signs should NOT be doubled when they not evaluated (e.g. Ansible docker_container module).
labels:
- "traefik.http.middlewares.test-auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
Configuration Options
Passwords must be hashed using MD5, SHA1, or BCrypt.
| Tip |
| Use htpasswd to generate the passwords |
- users
- An array of authorized users. Each user must be declared using the
name:hashed-passwordformat. The separator is a comma (,).
Nginx with Traefik
$ docker service create \
--network=traefik-net \
-l traefik.backend=webapp \
-l traefik.port=80 \
-l traefik.frontend.rule=Host:www.server-project.com \
nginx
docker-compose
- Zarathu Blog - Implementing a Reverse-Proxy with Docker and Traefik
- Docker container reverse proxy using traefik
- Running official MediaWiki docker container with Traefik reverse proxy on Project:Support desk
- traefik/whoami: Tiny Go webserver that prints os information and HTTP request to output - image for testing
Troubleshooting
Unable to obtain ACME certificate
time="2018-12-06T01:53:04Z" level=error msg="Unable to obtain ACME certificate for domains \"docker.bogo.local\" detected thanks to rule \"Host:docker.bogo.local\" : cannot obtain certificates: acme: Error 400 - urn:ietf:params:acme:error:malformed - Error creating new order :: Name does not end in a public suffix"
Gateway timeout
When working with Swarm, it is likely not connected to the Traefik-Network.
See also
- traefik-certificate-extractor
- Docker
- ACME
- Reverse proxy (Forward proxy; Edge Router)
- Consul
- Envoy
- Caddy
- HAProxy
- NGINX
Favorite site
- Joinc - traefik
- Managing Multiple Microservices with Traefik in Docker Swarm
- [Recommended] Docker Stack with Traefik
- Visualizing Traefik Metrics and HTTP Logs in Grafana - Traefik HTTP logging using InfluxDB, Promtail, Grafana, and Loki
with kubernetes
- [Recommended] Kube Ingress — Sharing Traefik test results. Sharing the results of Traefik tests validated for Kube Ingress… | by Jerry (Lee Jeong-hoon) | Medium
- 24. Kube training - Traefik Ingress L7 switch — Thinking slowly, aiming to be an engineer until 60.
- (Kubernetes) Implementing a secure service with Traefik v2 and cert-manager
- Caddy
- Computer Network
- ContinuousIntegration:ImplementationGuide
- DevOps:Kubernetes
- Docker
- Docker rollout
- Envoy
- GitLab
- Grafana
- InfluxDB
- Kubeflow:Architecture
- Kubeflow:Install
- Kubernetes:Basic
- Lets Encrypt
- Lightweight Kubernetes
- Load balancing
- Microservices
- NextCloud
- Nginx:ReverseProxy
- Proxy server
- Rivet
- SideKick
- Traefik-certificate-extractor
- Traefik:Docker
- Traefik:v2