Traefik (also called Traefik Proxy) is an open-source reverse proxy and load balancer written in Go that discovers backend services automatically and builds its routing table from the platforms where those services run. Among web servers used in front of modern applications, it stands out because it does not rely on a static configuration file for every route: it watches providers such as Docker and Kubernetes and reconfigures itself while running.
In the context of servers and hosting, Traefik usually sits at the edge of a container platform, terminates TLS, obtains certificates through the ACME protocol, and forwards HTTP, TCP or UDP traffic to the correct service. It is not a general-purpose web server for static files in the way Nginx or Apache is; its strength is dynamic routing for changing infrastructure.
How Traefik discovers and routes services
Traefik works by separating a static configuration, read once at startup, from a dynamic configuration that changes at runtime. The static part defines entrypoints (listening ports such as 80 and 443), enabled providers, logging and certificate resolvers. The dynamic part describes routers, middlewares and services, and Traefik receives it continuously from its providers.
A provider is a source of dynamic configuration. When a container starts with suitable labels, or a Kubernetes resource is created, the provider emits a new configuration snapshot and Traefik applies it without a restart. Requests then flow through a fixed chain of objects, summarized in the following table.
| Object | Role | Typical example |
|---|---|---|
| Entrypoint | Network port and protocol where traffic arrives | websecure on port 443 |
| Router | Matches requests by rules and selects a service | Host rule for app.example.com |
| Middleware | Modifies or filters the request before forwarding | Redirect to HTTPS, basic authentication |
| Service | Defines how to reach backends and balance load | Three container replicas, round robin |
| Provider | Supplies the dynamic configuration | Docker, Kubernetes CRD, file |
Router rules match on host names, paths, headers, query parameters or client IP ranges. When several routers match, Traefik evaluates them by priority, which by default follows the length of the rule, so more specific rules win over generic ones.
Providers, protocols and certificates
Traefik supports many configuration providers, and the choice of provider decides how operators declare routes. The table below lists the most common ones and the way each expresses routing intent.
| Provider | Where routes are declared | Typical environment |
|---|---|---|
| Docker | Container labels | Single host or Docker Compose stacks |
| Docker Swarm | Service labels in the swarm | Small clusters without Kubernetes |
| Kubernetes Ingress | Standard Ingress resources | Portable Kubernetes deployments |
| Kubernetes CRD | IngressRoute and Middleware objects | Kubernetes with advanced routing |
| Kubernetes Gateway API | Gateway and HTTPRoute resources | Newer, vendor-neutral Kubernetes setups |
| File | YAML or TOML files watched on disk | Virtual machines and static backends |
| Consul, etcd, Redis | Key-value store entries | Service meshes and custom platforms |
Beyond HTTP/1.1, HTTP/2 and HTTP/3, Traefik routes raw TCP and UDP streams, which allows it to front databases or message brokers. TCP routing relies on SNI (Server Name Indication) to select a backend when the connection is encrypted, because the proxy cannot inspect the HTTP host header in that case.
Automatic HTTPS is a defining feature. A certificate resolver requests and renews certificates from an ACME authority such as Let’s Encrypt, using the HTTP-01, TLS-ALPN-01 or DNS-01 challenge. DNS-01 is required for wildcard certificates. In the open-source edition, certificates are stored in a local acme.json file, which complicates running several Traefik instances that must share them.
How Traefik compares with other web servers
Traefik overlaps with other reverse proxies in this topic but follows a different design priority: automation and service discovery rather than raw throughput or static file serving. The comparison below highlights where each tool fits.
| Criterion | Traefik | Nginx | Caddy |
|---|---|---|---|
| Configuration model | Dynamic from providers | Static files, reload needed | Caddyfile or JSON API |
| Automatic TLS | Built in through ACME | External tools such as Certbot | Built in by default |
| Container discovery | Native, label based | Requires templates or controllers | Through plugins |
| Static file serving | Not intended for it | Highly efficient | Supported |
| Typical role | Edge router for containers | General web server and proxy | Simple HTTPS web server |
A frequent pattern combines the two approaches: Traefik handles ingress and certificates, while Nginx or an application server such as Gunicorn or Uvicorn runs inside each container. Traefik is therefore a reverse proxy, not an application server, and it never executes PHP, Python or other code.
Middlewares and operational features
Middlewares are reusable processing steps attached to routers, and they replace much of the custom logic that would otherwise sit in application code. Common middlewares include HTTPS redirection, header manipulation, rate limiting, IP allow lists, path prefix stripping, forward authentication to an external identity service, retries and circuit breakers.
- Health checks remove failing backends from a service until they recover.
- Load balancing supports weighted round robin, sticky sessions and mirroring of traffic.
- Observability covers access logs, Prometheus and OpenTelemetry metrics, and distributed tracing.
- The built-in dashboard shows active routers, services and middlewares in real time.
The dashboard and the API reveal the entire routing topology, so they must never be exposed without authentication. Operators normally publish them only on an internal entrypoint or protect them with a middleware.
Limitations and common mistakes
Traefik is convenient, but its automation introduces specific failure modes that differ from those of static servers. The table below lists frequent problems and their usual remedies.
| Symptom | Likely cause | Fix |
|---|---|---|
| 404 for a new container | Missing labels or wrong Docker network | Set traefik.enable and attach the shared network |
| Self-signed default certificate | ACME challenge failed or rate limited | Check DNS, open port 80, use the staging authority |
| Full host takeover risk | Docker socket mounted read-write | Use a socket proxy with restricted access |
| Certificates lost on restart | acme.json not on persistent storage | Mount a volume with file mode 600 |
| Unexpected route wins | Overlapping rules and default priority | Set explicit router priorities |
Other limits deserve attention. Very high request volumes of static content are usually served more efficiently by Nginx or a CDN. Configuration spread across hundreds of container labels can become hard to audit, and the move from Traefik v1 to v2 changed the configuration model completely, so older tutorials are often misleading.
Stripped to the essentials
Traefik is a smart front door for websites and apps that run in containers. Visitors knock on one door, and Traefik decides which room inside the building should answer, based on the web address they typed.
What makes it special is that it notices new rooms by itself. When a team starts a new app, Traefik sees it, creates the route and even fetches the security certificate that puts the padlock in the browser. Nobody has to edit a long settings file by hand each time something changes.
Where it is applied
A small software company runs about twenty internal and customer-facing services with Docker Compose on two virtual servers. Each service, such as the customer portal, the status page and an internal wiki, declares its host name in container labels, for example portal.example.com.
Traefik listens on ports 80 and 443, redirects all plain HTTP traffic to HTTPS, and uses a DNS-01 resolver to obtain a wildcard certificate. The wiki router adds a forward authentication middleware so that only employees signed in through the company identity provider can reach it, and a rate-limit middleware protects the public login page.
When developers deploy a new preview environment, it becomes reachable with valid HTTPS within seconds and without any proxy edit. The operations team reports fewer configuration errors, and certificate renewals no longer require manual work.