2019-02-26 13:50:07 +00:00
# Overview
What's Happening to the Requests?
{: .subtitle }
2019-05-17 11:32:05 +00:00
Let's zoom in on Traefik's architecture and talk about the components that enable the routes to be created.
2019-02-26 13:50:07 +00:00
2019-03-14 08:30:04 +00:00
First, when you start Traefik, you define [entrypoints ](../entrypoints ) (in their most basic forms, they are port numbers).
Then, connected to these entrypoints, [routers ](../routers ) analyze the incoming requests to see if they match a set of [rules ](../routers#rule ).
If they do, the router might transform the request using pieces of [middleware ](../middlewares/overview.md ) before forwarding them to your [services ](./services/index.md ).
2019-02-26 13:50:07 +00:00
![Architecture ](../assets/img/architecture-overview.png )
## Clear Responsibilities
2019-03-14 08:30:04 +00:00
- [_Providers_ ](../providers/overview.md ) discover the services that live on your infrastructure (their IP, health, ...)
2019-05-06 15:44:04 +00:00
- [_Entrypoints_ ](./entrypoints.md ) listen for incoming traffic (ports, ...)
2019-03-14 08:30:04 +00:00
- [_Routers_ ](./routers/index.md ) analyse the requests (host, path, headers, SSL, ...)
- [_Services_ ](./services/index.md ) forward the request to your services (load balancing, ...)
2019-02-26 13:50:07 +00:00
- [_Middlewares_ ](../middlewares/overview.md ) may update the request or make decisions based on the request (authentication, rate limiting, headers, ...)
2019-03-14 08:30:04 +00:00
2019-02-26 13:50:07 +00:00
## Example with a File Provider
Below is an example of a full configuration file for the [file provider ](../providers/file.md ) that forwards `http://domain/whoami/` requests to a service reachable on `http://private/whoami-service/` .
2019-03-14 08:30:04 +00:00
In the process, Traefik will make sure that the user is authenticated (using the [BasicAuth middleware ](../middlewares/basicauth.md )).
2019-02-26 13:50:07 +00:00
2019-06-26 16:18:04 +00:00
Static configuration:
2019-07-02 15:36:04 +00:00
```toml tab="File (TOML)"
2019-04-15 09:14:05 +00:00
[entryPoints]
2019-06-26 16:18:04 +00:00
[entryPoints.web]
# Listen on port 8081 for incoming requests
address = ":8081"
2019-02-26 13:50:07 +00:00
2019-03-14 08:30:04 +00:00
[providers]
2019-06-26 16:18:04 +00:00
# Enable the file provider to define routers / middlewares / services in a file
[providers.file]
2019-07-15 08:22:03 +00:00
filename = "dynamic_conf.toml"
2019-06-26 16:18:04 +00:00
```
2019-07-02 15:36:04 +00:00
```yaml tab="File (YAML)"
2019-07-01 09:30:05 +00:00
entryPoints:
2019-06-26 16:18:04 +00:00
web:
# Listen on port 8081 for incoming requests
address: :8081
2019-07-01 09:30:05 +00:00
2019-06-26 16:18:04 +00:00
providers:
# Enable the file provider to define routers / middlewares / services in a file
2019-07-15 08:22:03 +00:00
file:
filename: dynamic_conf.yml
2019-06-26 16:18:04 +00:00
```
2019-07-02 15:36:04 +00:00
```bash tab="CLI"
# Listen on port 8081 for incoming requests
--entryPoints.web.address=:8081
# Enable the file provider to define routers / middlewares / services in a file
2019-07-15 08:22:03 +00:00
--providers.file.filename=dynamic_conf.toml
2019-07-02 15:36:04 +00:00
```
2019-06-26 16:18:04 +00:00
Dynamic configuration:
```toml tab="TOML"
# http routing section
[http]
[http.routers]
# Define a connection between requests and services
[http.routers.to-whoami]
rule = "Host(`domain`) & & PathPrefix(`/whoami/`)"
# If the rule matches, applies the middleware
middlewares = ["test-user"]
# If the rule matches, forward to the whoami service (declared below)
service = "whoami"
[http.middlewares]
# Define an authentication mechanism
2019-07-01 09:30:05 +00:00
[http.middlewares.test-user.basicAuth]
2019-06-26 16:18:04 +00:00
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"]
[http.services]
# Define how to reach an existing service on our infrastructure
2019-07-01 09:30:05 +00:00
[http.services.whoami.loadBalancer]
[[http.services.whoami.loadBalancer.servers]]
2019-06-26 16:18:04 +00:00
url = "http://private/whoami-service"
```
```yaml tab="YAML"
# http routing section
http:
routers:
# Define a connection between requests and services
to-whoami:
rule: "Host(`domain`) & & PathPrefix(`/whoami/`)"
# If the rule matches, applies the middleware
middlewares:
- test-user
# If the rule matches, forward to the whoami service (declared below)
service: whoami
2019-07-01 09:30:05 +00:00
2019-06-26 16:18:04 +00:00
middlewares:
# Define an authentication mechanism
test-user:
basicAuth:
users:
- test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/
2019-07-01 09:30:05 +00:00
2019-06-26 16:18:04 +00:00
services:
# Define how to reach an existing service on our infrastructure
whoami:
2019-07-01 09:30:05 +00:00
loadBalancer:
2019-06-26 16:18:04 +00:00
servers:
- url: http://private/whoami-service
2019-02-26 13:50:07 +00:00
```
!!! note "The File Provider"
In this example, we use the [file provider ](../providers/file.md ).
Even if it is one of the least magical way of configuring Traefik, it explicitly describes every available notion.
2019-03-14 08:30:04 +00:00
!!! note "HTTP / TCP"
In this example, we've defined routing rules for http requests only.
Traefik also supports TCP requests. To add [TCP routers ](./routers/index.md ) and [TCP services ](./services/index.md ), declare them in a TCP section like in the following.
??? example "Adding a TCP route for TLS requests on whoami.traefik.io"
2019-06-26 16:18:04 +00:00
Static configuration:
2019-07-15 08:22:03 +00:00
```toml tab="File (TOML)"
2019-04-15 09:14:05 +00:00
[entryPoints]
2019-07-01 09:30:05 +00:00
[entryPoints.web]
# Listen on port 8081 for incoming requests
address = ":8081"
2019-03-14 08:30:04 +00:00
[providers]
2019-07-01 09:30:05 +00:00
# Enable the file provider to define routers / middlewares / services in a file
[providers.file]
2019-07-15 08:22:03 +00:00
filename = "dynamic_conf.toml"
2019-06-26 16:18:04 +00:00
```
2019-07-15 08:22:03 +00:00
```yaml tab="File (YAML)"
2019-07-01 09:30:05 +00:00
entryPoints:
2019-06-26 16:18:04 +00:00
web:
# Listen on port 8081 for incoming requests
address: :8081
providers:
# Enable the file provider to define routers / middlewares / services in a file
2019-07-15 08:22:03 +00:00
file:
filename: dynamic_conf.yml
2019-06-26 16:18:04 +00:00
```
2019-07-02 15:36:04 +00:00
```bash tab="CLI"
# Listen on port 8081 for incoming requests
--entryPoints.web.address=":8081"
# Enable the file provider to define routers / middlewares / services in a file
2019-07-15 08:22:03 +00:00
--providers.file.filename=dynamic_conf.toml
2019-07-02 15:36:04 +00:00
```
2019-06-26 16:18:04 +00:00
Dynamic configuration:
2019-03-14 08:30:04 +00:00
2019-06-26 16:18:04 +00:00
```toml tab="TOML"
# http routing section
[http]
2019-07-01 09:30:05 +00:00
[http.routers]
# Define a connection between requests and services
[http.routers.to-whoami]
rule = "Host(`domain`) & & PathPrefix(`/whoami/`)"
# If the rule matches, applies the middleware
middlewares = ["test-user"]
# If the rule matches, forward to the whoami service (declared below)
service = "whoami"
[http.middlewares]
# Define an authentication mechanism
[http.middlewares.test-user.basicAuth]
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"]
[http.services]
# Define how to reach an existing service on our infrastructure
[http.services.whoami.loadBalancer]
[[http.services.whoami.loadBalancer.servers]]
url = "http://private/whoami-service"
[tcp]
[tcp.routers]
[tcp.routers.to-whoami-tcp]
rule = "HostSNI(`whoami-tcp.traefik.io`)"
service = "whoami-tcp"
[tcp.routers.to-whoami-tcp.tls]
[tcp.services]
[tcp.services.whoami-tcp.loadBalancer]
[[tcp.services.whoami-tcp.loadBalancer.servers]]
address = "xx.xx.xx.xx:xx"
2019-03-14 08:30:04 +00:00
```
2019-06-26 16:18:04 +00:00
```yaml tab="YAML"
# http routing section
http:
2019-07-01 09:30:05 +00:00
2019-06-26 16:18:04 +00:00
routers:
# Define a connection between requests and services
to-whoami:
rule: Host(`domain`) & & PathPrefix(`/whoami/`)
# If the rule matches, applies the middleware
middlewares:
- test-user
# If the rule matches, forward to the whoami service (declared below)
service: whoami
2019-07-01 09:30:05 +00:00
2019-06-26 16:18:04 +00:00
middlewares:
# Define an authentication mechanism
test-user:
basicAuth:
users:
- test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/
2019-07-01 09:30:05 +00:00
2019-06-26 16:18:04 +00:00
services:
# Define how to reach an existing service on our infrastructure
whoami:
2019-07-01 09:30:05 +00:00
loadBalancer:
2019-06-26 16:18:04 +00:00
servers:
- url: http://private/whoami-service
tcp:
2019-07-01 09:30:05 +00:00
2019-06-26 16:18:04 +00:00
routers:
to-whoami-tcp:
service: whoami-tcp
rule: HostSNI(`whoami-tcp.traefik.io`)
2019-07-01 09:30:05 +00:00
2019-06-26 16:18:04 +00:00
services:
whoami-tcp:
2019-07-01 09:30:05 +00:00
loadBalancer:
2019-06-26 16:18:04 +00:00
servers:
- address: xx.xx.xx.xx:xx
```