API Definition

Configuration

  1. # API definition
  2. # Warning: Enabling API will expose Traefik's configuration.
  3. # It is not recommended in production,
  4. # unless secured by authentication and authorizations
  5. [api]
  6. # Name of the related entry point
  7. #
  8. # Optional
  9. # Default: "traefik"
  10. #
  11. entryPoint = "traefik"
  12. # Enable Dashboard
  13. #
  14. # Optional
  15. # Default: true
  16. #
  17. dashboard = true
  18. # Enable debug mode.
  19. # This will install HTTP handlers to expose Go expvars under /debug/vars and
  20. # pprof profiling data under /debug/pprof/.
  21. # Additionally, the log level will be set to DEBUG.
  22. #
  23. # Optional
  24. # Default: false
  25. #
  26. debug = true

For more customization, see entry points documentation and the examples below.

Dashboard (Web UI)

Web UI Providers

Web UI Health

Security

Enabling the API will expose all configuration elements, including sensitive data.

It is not recommended in production, unless secured by authentication and authorizations.

A good sane default (but not exhaustive) set of recommendations would be to apply the following protection mechanism:

API

Path Method Description
/ GET Provides a simple HTML frontend of Traefik
/cluster/leader GET JSON leader true/false response
/health GET JSON health metrics
/api GET Configuration for all providers
/api/providers GET Providers
/api/providers/{provider} GET, PUT Get or update provider (1)
/api/providers/{provider}/backends GET List backends
/api/providers/{provider}/backends/{backend} GET Get backend
/api/providers/{provider}/backends/{backend}/servers GET List servers in backend
/api/providers/{provider}/backends/{backend}/servers/{server} GET Get a server in a backend
/api/providers/{provider}/frontends GET List frontends
/api/providers/{provider}/frontends/{frontend} GET Get a frontend
/api/providers/{provider}/frontends/{frontend}/routes GET List routes in a frontend
/api/providers/{provider}/frontends/{frontend}/routes/{route} GET Get a route in a frontend

<1> See Rest for more information.

Warning

For compatibility reason, when you activate the rest provider, you can use web or rest as provider value. But be careful, in the configuration for all providers the key is still web.

Address / Port

You can define a custom address/port like this:

  1. defaultEntryPoints = ["http"]
  2. [entryPoints]
  3. [entryPoints.http]
  4. address = ":80"
  5. [entryPoints.foo]
  6. address = ":8082"
  7. [entryPoints.bar]
  8. address = ":8083"
  9. [ping]
  10. entryPoint = "foo"
  11. [api]
  12. entryPoint = "bar"

In the above example, you would access a regular path, dashboard, and health-check as follows:

In the above example, it is very important to create a named dedicated entry point, and do not include it in defaultEntryPoints. Otherwise, you are likely to expose all services via that entry point.

Custom Path

You can define a custom path like this:

  1. defaultEntryPoints = ["http"]
  2. [entryPoints]
  3. [entryPoints.http]
  4. address = ":80"
  5. [entryPoints.foo]
  6. address = ":8080"
  7. [entryPoints.bar]
  8. address = ":8081"
  9. # Activate API and Dashboard
  10. [api]
  11. entryPoint = "bar"
  12. dashboard = true
  13. [file]
  14. [backends]
  15. [backends.backend1]
  16. [backends.backend1.servers.server1]
  17. url = "http://127.0.0.1:8081"
  18. [frontends]
  19. [frontends.frontend1]
  20. entryPoints = ["foo"]
  21. backend = "backend1"
  22. [frontends.frontend1.routes.test_1]
  23. rule = "PathPrefixStrip:/yourprefix;PathPrefix:/yourprefix"

Authentication

You can define the authentication like this:

  1. defaultEntryPoints = ["http"]
  2. [entryPoints]
  3. [entryPoints.http]
  4. address = ":80"
  5. [entryPoints.foo]
  6. address=":8080"
  7. [entryPoints.foo.auth]
  8. [entryPoints.foo.auth.basic]
  9. users = [
  10. "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
  11. "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
  12. ]
  13. [api]
  14. entrypoint="foo"

For more information, see entry points .

Provider call example

  1. curl -s "http://localhost:8080/api" | jq .
  1. {
  2. "file": {
  3. "frontends": {
  4. "frontend2": {
  5. "routes": {
  6. "test_2": {
  7. "rule": "Path:/test"
  8. }
  9. },
  10. "backend": "backend1"
  11. },
  12. "frontend1": {
  13. "routes": {
  14. "test_1": {
  15. "rule": "Host:test.localhost"
  16. }
  17. },
  18. "backend": "backend2"
  19. }
  20. },
  21. "backends": {
  22. "backend2": {
  23. "loadBalancer": {
  24. "method": "drr"
  25. },
  26. "servers": {
  27. "server2": {
  28. "weight": 2,
  29. "URL": "http://172.17.0.5:80"
  30. },
  31. "server1": {
  32. "weight": 1,
  33. "url": "http://172.17.0.4:80"
  34. }
  35. }
  36. },
  37. "backend1": {
  38. "loadBalancer": {
  39. "method": "wrr"
  40. },
  41. "circuitBreaker": {
  42. "expression": "NetworkErrorRatio() > 0.5"
  43. },
  44. "servers": {
  45. "server2": {
  46. "weight": 1,
  47. "url": "http://172.17.0.3:80"
  48. },
  49. "server1": {
  50. "weight": 10,
  51. "url": "http://172.17.0.2:80"
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }

Cluster Leadership

  1. curl -s "http://localhost:8080/cluster/leader" | jq .
  1. < HTTP/1.1 200 OK
  2. < Content-Type: application/json; charset=UTF-8
  3. < Date: xxx
  4. < Content-Length: 15

If the given node is not a cluster leader, an HTTP status of 429-Too-Many-Requests will be returned.

  1. {
  2. // current leadership status of the queried node
  3. "leader": true
  4. }

Health

  1. curl -s "http://localhost:8080/health" | jq .
  1. {
  2. // Traefik PID
  3. "pid": 2458,
  4. // Traefik server uptime (formated time)
  5. "uptime": "39m6.885931127s",
  6. // Traefik server uptime in seconds
  7. "uptime_sec": 2346.885931127,
  8. // current server date
  9. "time": "2015-10-07 18:32:24.362238909 +0200 CEST",
  10. // current server date in seconds
  11. "unixtime": 1444235544,
  12. // count HTTP response status code in realtime
  13. "status_code_count": {
  14. "502": 1
  15. },
  16. // count HTTP response status code since Traefik started
  17. "total_status_code_count": {
  18. "200": 7,
  19. "404": 21,
  20. "502": 13
  21. },
  22. // count HTTP response
  23. "count": 1,
  24. // count HTTP response
  25. "total_count": 41,
  26. // sum of all response time (formated time)
  27. "total_response_time": "35.456865605s",
  28. // sum of all response time in seconds
  29. "total_response_time_sec": 35.456865605,
  30. // average response time (formated time)
  31. "average_response_time": "864.8016ms",
  32. // average response time in seconds
  33. "average_response_time_sec": 0.8648016000000001,
  34. // request statistics [requires --api.statistics to be set]
  35. // ten most recent requests with 4xx and 5xx status codes
  36. "recent_errors": [
  37. {
  38. // status code
  39. "status_code": 500,
  40. // description of status code
  41. "status": "Internal Server Error",
  42. // request HTTP method
  43. "method": "GET",
  44. // request hostname
  45. "host": "localhost",
  46. // request path
  47. "path": "/path",
  48. // RFC 3339 formatted date/time
  49. "time": "2016-10-21T16:59:15.418495872-07:00"
  50. }
  51. ]
  52. }

Dashboard Statistics

You can control how the Traefik's internal metrics are shown in the Dashboard.

If you want to export internal metrics to different monitoring systems, please check the page Metrics.

  1. [api]
  2. # ...
  3. # Enable more detailed statistics.
  4. [api.statistics]
  5. # Number of recent errors logged.
  6. #
  7. # Default: 10
  8. #
  9. recentErrors = 10
  10. # ...
Path Method Description
/metrics GET Export internal metrics