harbor run -t LiteCoder/nginx-proxy-multi-service-dockerharbor download LiteCoder/nginx-proxy-multi-service-dockerCreate a multi-container web application using Docker Compose. Nginx acts as a reverse proxy, routing traffic to three backend services based on URL paths: a static website, a Node.js Express API, and a Python Flask API.
All files must be created under /app/ with the following layout:
/app/
├── docker-compose.yml
├── nginx/
│ └── nginx.conf
├── static-site/
│ ├── Dockerfile
│ └── index.html
├── node-api/
│ ├── Dockerfile
│ ├── package.json
│ └── server.js
└── flask-api/
├── Dockerfile
├── requirements.txt
└── app.py
"3" (or compatible)docker-compose.yml1. Static Site (static-site)
/app/static-site/index.html must contain:
<h1> element with the exact text: Welcome to the Multi-Service App<p> element with id timestamp2. Node.js API (node-api)
GET / endpoint that returns JSON with at least these fields:
service (string): must be "node-api"timestamp (string): current ISO 8601 timestamphostname (string): the container hostnameContent-Type must be application/json3. Flask API (flask-api)
GET / endpoint that returns JSON with at least these fields:
service (string): must be "flask-api"timestamp (string): current ISO 8601 timestamppython_version (string): the running Python versionContent-Type must be application/jsonConfigure Nginx in /app/nginx/nginx.conf with the following location-based routing:
| URL Path Prefix | Upstream Service | Behavior |
|---|---|---|
/ |
static-site:80 |
Serve the static website (exact / or static assets) |
/api/node/ |
node-api:3000 |
Proxy to Node.js API, stripping the /api/node prefix |
/api/flask/ |
flask-api:5000 |
Proxy to Flask API, stripping the /api/flask prefix |
After docker compose up -d (or docker-compose up -d), the following requests through the host must succeed:
curl http://localhost:8080/ → returns the static HTML page containing Welcome to the Multi-Service Appcurl http://localhost:8080/api/node/ → returns JSON with "service": "node-api"curl http://localhost:8080/api/flask/ → returns JSON with "service": "flask-api"Dockerfilestatic-site/Dockerfile: use a lightweight base image to serve static filesnode-api/Dockerfile: use a Node.js base image, install dependencies via npm install, and start the serverflask-api/Dockerfile: use a Python base image, install dependencies via pip install, and start the Flask appdocker compose up -d from /app/ starts all four containers (nginx, static-site, node-api, flask-api) successfullyhttp://localhost:8080/ returns HTML containing Welcome to the Multi-Service Apphttp://localhost:8080/api/node/ returns valid JSON with a service field equal to "node-api"http://localhost:8080/api/flask/ returns valid JSON with a service field equal to "flask-api"