Skip to main content

HTTP Overview

HTTP Middlewares Overview

forwardHTTP authMiddlewares in Traefik let you modify requests and responses on the fly. You can configure them in multiple ways (Docker labels, TOML, YAML, etc.).

https:

Configuration Example in a docker-compose.yaml


# As a Docker Label
whoami:
  # A container that exposes an API to show its IP address
  image: traefik/whoami
  labels:
    # Create a middleware named `foo-add-prefix`
    - "traefik.http.middlewares.foo-add-prefix.addprefix.prefix=/foo"
    # Apply the middleware named `foo-add-prefix` to the router named `router1`
    - "traefik.http.routers.router1.middlewares=foo-add-prefix@docker"

Configuration Example in a dynamic.toml


[http.routers]
  [http.routers.router1]
    service = "service1"
    middlewares = ["foo-add-prefix"]
    rule = "Host(`example.com`)"

[http.middlewares]
  [http.middlewares.foo-add-prefix.addPrefix]
    prefix = "/foo"

[http.services]
  [http.services.service1]
    [http.services.service1.loadBalancer]

      [[http.services.service1.loadBalancer.servers]]
        url = "http://doc.traefik.io/traefik/middlewares/http/forwardauth/

127.0.0.1:80"

Configuration Example in a dynamic.yml


http:
  routers:
    router1:
      service: service1
      middlewares:
        - "foo-add-prefix"
      rule: "Host(`example.com`)"

  middlewares:
    foo-add-prefix:
      addPrefix:
        prefix: "/foo"

  services:
    service1:
      loadBalancer:
        servers:
          - url: "http://127.0.0.1:80"

Available HTTP Middlewares

MiddlewarePurposeArea
AddPrefixAdds a Path PrefixPath Modifier
BasicAuthAdds Basic AuthenticationSecurity, Authentication
BufferingBuffers the request/responseRequest Lifecycle
ChainCombines multiple pieces of middlewareMisc
CircuitBreakerPrevents calling unhealthy servicesRequest Lifecycle
CompressCompresses the responseContent Modifier
ContentTypeHandles Content-Type auto-detectionMisc
DigestAuthAdds Digest AuthenticationSecurity, Authentication
ErrorsDefines custom error pagesRequest Lifecycle
ForwardAuthDelegates AuthenticationSecurity, Authentication
HeadersAdds / Updates headersSecurity
IPAllowListLimits the allowed client IPsSecurity, Request lifecycle
InFlightReqLimits the number of simultaneous connectionsSecurity, Request lifecycle
PassTLSClientCertAdds Client Certificates in a HeaderSecurity
RateLimitLimits the call frequencySecurity, Request lifecycle
RedirectSchemeRedirects based on schemeRequest lifecycle
RedirectRegexRedirects based on regexRequest lifecycle
ReplacePathChanges the path of the requestPath Modifier
ReplacePathRegexChanges the path of the requestPath Modifier
RetryAutomatically retries in case of errorRequest lifecycle
StripPrefixChanges the path of the requestPath Modifier
StripPrefixRegexChanges the path of the requestPath Modifier

For even more options, check out the  community-contributed plugins  in the plugin catalog.