The Nginx gateway is the unified entry point for every request in Shop Microservers. Clients — whether a browser, the Next.js frontend, or an API tool — connect to a single address on port 80. Nginx inspects the URL prefix and forwards the request to the appropriate upstream container over Docker’s internal network. This design keeps all microservices off the public network, normalizes host headers, and provides a convenientDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/astrxnomo/shop-microservers/llms.txt
Use this file to discover all available pages before exploring further.
/health endpoint used by Docker Compose to verify the gateway itself is alive before marking the stack as ready.
Overview
Container
Built from
./gateway/Dockerfile. Listens on port 80 (configurable via GATEWAY_PORT in docker-compose.yml).Role
Single entry point for all client traffic. Routes by URL prefix to the appropriate upstream service.
DNS Resolver
Uses Docker’s embedded DNS at
127.0.0.11 with a 30s valid TTL so upstream containers can be resolved by their service name.Startup Order
The gateway container only starts after all four microservices pass their own
/health checks, enforced via depends_on in docker-compose.yml.Routing Table
All traffic enters through port 80. Nginx strips the matching location prefix and proxies the remainder to the upstream.| Path Prefix | Upstream Name | Internal Address |
|---|---|---|
/api/auth/ | auth_service | auth:3004 |
/api/catalog/ | catalog_service | catalog:3001 |
/api/cart/ | cart_service | cart:3002 |
/api/orders/ | orders_service | orders:3003 |
/ | frontend_app | frontend:3000 |
/health | (inline) | Returns 200 ok |
Because each location uses
proxy_pass http://upstream_name/, the path prefix is stripped before forwarding. A request to /api/auth/login reaches the auth service as /login.nginx.conf
WebSocket Support
The catch-alllocation / block that forwards to the Next.js frontend includes WebSocket upgrade headers:
Health Endpoint
The gateway exposes a dedicated health check atGET /health:
200 OK with the plain-text body ok without touching any upstream. It is used by Docker Compose healthcheck configurations to determine whether the gateway container is ready to accept traffic.
DNS Resolution
127.0.0.11 is Docker’s embedded DNS server. Setting valid=30s tells Nginx to re-resolve upstream hostnames every 30 seconds, which is important during rolling restarts: if a service container is replaced, Nginx will pick up the new IP within 30 seconds rather than caching a stale address indefinitely.
Startup Dependencies
Forwarded Headers
Every proxied request receives three additional headers set by Nginx:| Header | Value | Purpose |
|---|---|---|
Host | $host | Preserves the original Host header |
X-Real-IP | $remote_addr | The client’s true IP address |
X-Forwarded-For | $proxy_add_x_forwarded_for | Appended IP chain for multi-hop proxies |