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.
basic_authHTTP Basic authentication with htpasswd hashes.
blockBlock methods or paths.
corsCORS headers and preflight handling.
decompressDecompress gzip request bodies.
dns_pathRoute to DNS-resolved instances selected from the path.
folderServe files and SPA assets from a directory.
forwardForward proxy for HTTP and CONNECT requests.
grpcuiBrowser UI for gRPC services.
gzipCompress responses.
headersSet or delete request/response headers.
helloReturn a static or templated response.
iamEmbedded IAM API/UI and permission store.
iam_checkCheck request authorization through an IAM API.
iam_forward_authForward-auth endpoint for external proxies.
infoReturn cookie or session value content.
injectRewrite response bodies by path.
logLightweight request log line.
loginLogin UI and OAuth2 code/password flows backed by session.
oauth2OAuth2/OIDC-compatible endpoints backed by IAM.
pathReplace the request path and optionally set request headers.
printPrint POST bodies to stderr for debugging.
rate_limitLimit requests by all traffic, IP, or real IP.
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.
roleCheck roles in parsed claims.
role_checkPath/method role authorization after session.
role_dataReturn data based on roles in parsed claims.
scopeCheck scopes in parsed claims.
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.
splitterSelect a sub-chain using expressions.
strip_prefixRemove one of several path prefixes.
templateRender a response body template.
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.