Path Based Routing
Routes by URL path prefix
Category: Practical
Task: Route requests by URL path
Prerequisites: Praxis runtime; Two HTTP backends reachable from the proxy
Expected outcome: Requests matching configured path prefixes reach their selected backend.
Run it: Use ghcr.io/praxis-proxy/praxis:0.7.2 and follow the first reverse-proxy tutorial to mount and start the configuration.
This configuration comes from the selected release. The example has not been run here; external services are not bundled.
Download the source file.
# Path-Based Routing
#
# Routes by URL path prefix. Longest prefix wins.
# /api/* -> api cluster
# /static/* -> static cluster
# /* -> default cluster
#
# Also demonstrates:
# - Exact path matching via conditions (path: "/healthz")
# - Method-based filtering via conditions (methods: [GET, HEAD])
#
# The router itself uses path_prefix for matching. Exact path
# and method constraints are applied via the condition system on
# individual filters.
#
listeners:
- name: default
address: "127.0.0.1:8080"
filter_chains:
- main
filter_chains:
- name: main
filters:
- filter: router
routes:
- path_prefix: "/api/"
cluster: api
- path_prefix: "/static/"
cluster: static
- path_prefix: "/"
cluster: default
# Exact path match: only /healthz (not /healthz/deep).
- filter: headers
response_set:
- name: "X-Health-Check"
value: "ok"
conditions:
- when:
path: "/healthz"
# Method constraint: add cache headers for read-only requests.
- filter: headers
response_set:
- name: "Cache-Control"
value: "public, max-age=300"
conditions:
- when:
path_prefix: "/static/"
methods: [GET, HEAD]
- filter: load_balancer
clusters:
- name: api
endpoints:
- "127.0.0.1:3001"
- "127.0.0.1:3002"
- "127.0.0.1:3003"
- name: static
endpoints:
- "127.0.0.1:4000"
- name: default
endpoints:
- "127.0.0.1:5000"
insecure_options:
allow_private_endpoints: true # example proxies to local backends