liveBook · Manning

Path-based routing

As explained in Learn Docker in a Month of Lunches, Second Edition

Path-based routing directs requests to different backend services according to the request URL path.

Path-based routing lets a reverse proxy direct URL paths to different backend containers. An image-gallery site can serve its web UI and REST API from separate containers while clients use one domain. section 20.2

A practical Nginx workflow is:

  • Add the site domain to the local hosts file and start the application containers. section 20.2
  • Install the Nginx site configuration that adds an API path, then reload Nginx. section 20.2
  • Request the API through the shared domain, such as /api/image, and verify that the API container responds. section 20.2
# remove the original image-gallery configuration:
rm ./nginx/sites-enabled/image-gallery.local
# copy in the new one, which adds the API, and reload nginx:
cp ./nginx/sites-available/image-gallery-2.local `
 ./nginx/sites-enabled/image-gallery.local
docker exec nginx-nginx-1 nginx -s reload
curl -i http:/./image-gallery.local/api/image

Use the configuration replacement, Nginx reload, and curl command to test path-based API routing. section 20.2

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Walks through configuration replacement, proxy reload, and curl verification without detailing Nginx matching internals.
Examples
Demonstrates an image-gallery web UI and API exposed through image-gallery.local and /api/image.
What it assumes
Assumes a Dockerized application, Nginx reverse proxy, local domain mapping, and an existing site configuration.
What you can do after
Operate Nginx path routing by installing a site configuration, reloading the proxy, and testing an API URL.
How it connects
Connects reverse proxies, REST APIs, containers, load balancing, and SSL termination.

Also explained in

Compare how 2 books explain path-based routing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.