Skip to content

HTTP Middlewares ​

HTTP middleware instances are declared under server.http.middlewares and referenced by name from routers.

yaml
server:
  http:
    middlewares:
      strip_api:
        strip_prefix:
          prefix: /api
      backend:
        service:
          loadbalancer:
            servers:
              - url: http://localhost:3000
    routers:
      app:
        path: /api/*
        middlewares:
          - strip_api
          - backend

Important Rule ​

A single named middleware can hold only one middleware type. If you need both headers and a service proxy, define two named middlewares and chain them in the router.

Supported Keys ​

KeyPurpose
access_logStructured request/response logging.
add_prefixAdd a path prefix before the next middleware.
authPostgreSQL-backed unified IAM/OAuth2 middleware.
basic_authHTTP Basic authentication with htpasswd hashes.
blockBlock methods or paths.
body_limitReject request bodies larger than a size.
cacheCache upstream responses in memory or Redis following Cache-Control.
canarySplit traffic between middleware chains by weight, sticky per client.
circuit_breakerStop calling a failing upstream for a while and answer 503.
compressCompress responses with zstd, Brotli or gzip.
concurrency_limitLimit requests handled at the same time, with an optional queue.
corsCORS headers and preflight handling.
csrfReject cross-site requests; optional double-submit token.
decompressDecompress gzip, Brotli or zstd request bodies.
dns_pathRoute to DNS-resolved instances selected from the path.
errorsReplace error responses with custom pages from config, a directory or a service.
fault_injectionDelay or fail a share of requests for resilience testing.
file_managerBrowse, edit, upload and move files in a directory through a UI; serve them by path.
folderServe files and SPA assets from a directory.
forwardForward proxy for HTTP and CONNECT requests.
forward_authAsk an external auth service (Authelia, oauth2-proxy, …) whether a request may pass.
gatewayRoute by path, method, header and query with Gateway API style filters and weighted backends.
gcp_tokenGoogle Cloud token via X.509 workload identity federation (OAuth2 endpoint or header inject).
grpcuiBrowser UI for gRPC services.
gzipDeprecated, use compress.
headersSet, append or delete request/response headers.
helloReturn a static or templated response.
iam_checkCheck request authorization through an IAM API.
iam_forward_authForward-auth endpoint for external proxies.
idempotencyAnswer repeated requests with the same Idempotency-Key with the stored response.
infoReturn cookie or session value content.
injectRewrite response bodies by path.
ip_filterAllow or deny requests by client IP or CIDR.
jwtValidate bearer JWTs with a JWKS URL, public keys or a secret.
logLightweight request log line.
loginLogin UI and OAuth2 code/password flows backed by session.
maintenanceAnswer with a maintenance response, switched by config or a file.
oauth2_resourceProtect an upstream (e.g. an MCP server) as an OAuth2 resource server (RFC 9728).
pathReplace the request path and optionally set request headers.
printPrint POST bodies to stderr for debugging.
rate_limitLimit requests by IP, header, path and other keys, in memory or shared through Redis.
real_ipUse the client IP sent by trusted proxies as the request address.
redirect_continueRedirect when a regex rewrite changes the URL, otherwise continue.
redirectionAlways redirect.
regex_pathRewrite the URL path with a regex.
requestMake an outbound HTTP request and return its response.
request_idEnsure X-Request-Id exists.
retrySend a request again with backoff when the upstream fails.
roleRole authorization (global and per path/method) and role based data after session.
scopeCheck scopes in parsed claims.
secure_headersHSTS, CSP with nonces and other security headers with safe defaults.
serviceReverse proxy and load balancer.
sessionValidate bearer/session tokens and set identity headers.
session_infoReturn selected claims from a session token.
setSet Turna request-context values for other middlewares.
signed_urlAllow requests with a valid, unexpired HMAC signature in the query.
splitterSelect a sub-chain using expressions.
strip_prefixRemove one of several path prefixes.
telemetryOpenTelemetry traces and metrics of requests.
templateRender a response body template.
timeoutBound request time with 504, per path prefix.
token_passGenerate a JWT and redirect or call another service.
tryRetry a chain with a rewritten path for selected response statuses.
urlModify scheme, host, path, query, fragment, and port by rule.
viewServe a combined Swagger/API documentation UI.
webhook_signatureVerify HMAC signatures of webhooks (GitHub, Stripe, Slack, Shopify, Standard Webhooks).
whoamiEcho server, host and request details, like traefik/whoami.