First Proxy
Route requests to two backends
This walkthrough extends the quickstart: one listener sends requests under /catalog/ to a second backend and every other path to the first, and you check which backend answers each request.
Switching projects opens that project’s default documentation release.
Versions marked “overview” do not contain this page. Selecting one opens that version’s documentation overview.
On this page
This walkthrough extends the quickstart: one listener sends
requests under /catalog/ to a second backend and every other path to the
first, and you check which backend answers each request. It uses the same
image, working directory and backend.yaml.
Before you start
Complete the quickstart, including its clean-up step, so port 8080, the container names and the
praxis-quickstartnetwork are free. KeepPRAXIS_IMAGEexported and stay in the working directory that holdsbackend.yaml.Write the configs
The second backend is a copy of the first with a different response body:
sed 's/quickstart-backend/catalog-backend/' backend.yaml > catalog.yamlSave the proxy configuration as
routes.yaml:admin: metrics_address: "127.0.0.1:9902" listeners: - name: web address: "0.0.0.0:8080" filter_chains: [main] filter_chains: - name: main filters: - filter: router routes: - path_prefix: "/" cluster: backend - path_prefix: "/catalog/" cluster: catalog - filter: load_balancer clusters: - name: backend endpoints: - "backend:8080" trusted_private_endpoints: - "backend" - name: catalog endpoints: - "catalog:8080" trusted_private_endpoints: - "catalog"The
routerpicks a cluster for each request, and theload_balancerpicks an endpoint in that cluster. The longest matching prefix wins, whatever the order of the routes, so/catalog/itemsgoes tocatalogand/falls back tobackend. Each cluster trusts only its own container name; see the quickstart for whytrusted_private_endpointsis needed.Check the proxy config before starting it:
docker run --rm -v "$PWD/routes.yaml:/etc/praxis/config.yaml:ro" \ "$PRAXIS_IMAGE" --validateThe command prints nothing and exits with status 0 when the config is valid. On SELinux hosts, append
,Zto each volume option (:ro,Z).Start the backends and the proxy
docker network create praxis-quickstart docker run -d --rm --name backend --network praxis-quickstart \ -v "$PWD/backend.yaml:/etc/praxis/config.yaml:ro" \ "$PRAXIS_IMAGE" docker run -d --rm --name catalog --network praxis-quickstart \ -v "$PWD/catalog.yaml:/etc/praxis/config.yaml:ro" \ "$PRAXIS_IMAGE" docker run -d --rm --name praxis --network praxis-quickstart \ -p 127.0.0.1:8080:8080 \ -v "$PWD/routes.yaml:/etc/praxis/config.yaml:ro" \ "$PRAXIS_IMAGE"Send a request to each route
A path under
/catalog/reaches the catalog backend:curl --fail-with-body http://127.0.0.1:8080/catalog/items{"source":"catalog-backend"}Any other path matches the
/fallback:curl --fail-with-body http://127.0.0.1:8080/{"source":"quickstart-backend"}Prefixes match whole path segments, and a trailing slash on the prefix makes no difference:
/catalogand/catalog/itemsgo tocatalog, while/cataloguegoes tobackend. Usepathinstead ofpath_prefixfor an exact match.Clean up
docker stop praxis catalog backend docker network rm praxis-quickstartDelete
catalog.yamlandroutes.yamlwhen you no longer need them.Next steps
- Router filter: host and header matching, exact paths and per-route retries.
- Load balancing: several endpoints per cluster, strategies and weights.
- Rehearse a reload: change a running proxy’s routes without a restart.