Nginx + Docker
Nginx running from the official Docker image as reverse proxy, TLS terminator and static file server in front of containerised apps.
- NGINX
- Docker
- Learning curve
- Moderate
- Status
- Mature and maintained
- Reviewed
- November 2026
- Best for
- Single-host or small multi-container deployments that need TLS and path or host routing
- Serving built SPA or static-site assets from a small image
- Adding rate limiting, caching and security headers in front of an app server
- Teams comfortable with config files who want a predictable, low-memory proxy
- Not ideal for
- Routing for frequently changing containers
Overview
This stack runs Nginx in a container on the same Docker network as the application containers it fronts. Nginx terminates TLS, serves static assets and proxies requests to upstream containers by service name, with configuration mounted from the host or baked into a custom image. It is the usual edge for apps deployed with Docker or Compose on VMs, and the `nginx:alpine` image doubles as a small static file server in multi-stage frontend builds.
What's inside
A basic reverse-proxy config is short, but location matching order, directive inheritance, proxy header handling and Docker networking take practice before configs behave as expected.
NGINX
Infrastructure
Hosts, deploys or connects the system
Learning: Moderate
Status: Active
Docker
Infrastructure
Hosts, deploys or connects the system
Learning: Easy
Status: Active
How it works
Clients hit Nginx on ports 80 and 443; Nginx terminates TLS, serves static files directly and proxies dynamic requests over a Docker network to upstream containers resolved through Docker's embedded DNS.
- 1.
Other to infrastructure
The container starts from a pinned `nginx` or `nginx:alpine` tag; the entrypoint renders `*.template` files in `/etc/nginx/templates` with envsubst, then Nginx loads `nginx.conf` and `conf.d/`.
- 2.
Other to infrastructure
A client connects to the published port; Nginx's event-driven workers accept it, terminate TLS with certificates mounted from the host (typically issued by certbot or another ACME client) and match a `server` and `location` block.
- 3.
Infrastructure to infrastructure
Static assets are served straight from a mounted volume or files copied into the image, with cache headers, gzip and `try_files` fallbacks set in config.
- 4.
Infrastructure to backend
Dynamic requests go through `proxy_pass` to an `upstream` of app containers, addressed by service name on a user-defined Docker network and balanced round-robin or by least connections.
- 5.
Backend to infrastructure
Responses flow back through Nginx, which can buffer, cache (`proxy_cache`) or compress them; access and error logs go to stdout and stderr so `docker logs` and log shippers collect them.
Strengths and drawbacks
Strengths
Efficient with many connections
Nginx's event-driven workers handle large numbers of concurrent keep-alive and slow clients with modest memory, shielding app servers such as Gunicorn, Puma or PHP-FPM from them.
Mature built-in feature set
Reverse proxying, TLS, HTTP/2, gzip, rate limiting (`limit_req`), response caching and WebSocket upgrades are all in the open-source build and thoroughly documented.
Small, standard images
The official image ships Debian and Alpine variants, logs to stdout and stderr and supports env-var config templates, so configuration is the only thing teams add.
Config reloads without dropped requests
`nginx -t` validates config, and `nginx -s reload` (or SIGHUP to the container) starts new workers while old ones finish in-flight requests.
Drawbacks
Upstream names resolve at startup
Nginx resolves upstream hostnames when it loads config: it refuses to start if an app container is not up yet ('host not found in upstream') and keeps proxying to stale IPs after a container is recreated. Use `resolver 127.0.0.11` with a variable in `proxy_pass`, or reload after deploys.
No container discovery
Unlike Traefik or Caddy, Nginx does not read Docker labels to pick up new services, and certificate renewal is usually scripted with certbot plus a reload; every new service means a config change.
Config bugs are silent
A trailing slash in `proxy_pass`, a missing `proxy_set_header Host` or `X-Forwarded-Proto`, or `if` inside `location` causes subtle routing and redirect bugs that `nginx -t` will not catch.
Some features are NGINX plus only
Active health checks, the API for changing upstreams at runtime and the live dashboard are commercial NGINX Plus features; the open-source build only marks upstreams down passively via `max_fails`.
Scores
Editorial ratings out of 10, comparable across every stack in the guide. They are judgement, not benchmarks. How we score
- Speed of building
- 7.2 out of 10, catalog average 7.7
- Ease of learning
- 7.4 out of 10, catalog average 7.2
- Scalability
- 7.2 out of 10, catalog average 7.6
- Performance
- 9.2 out of 10, catalog average 7.5
- Maintainability
- 6.6 out of 10, catalog average 7.2
- Ecosystem
- 8.6 out of 10, catalog average 8.2
- Flexibility
- 7.2 out of 10, catalog average 7.4
How quickly a team ships features
Higher means easier to pick up
How far it grows before a redesign
Speed of the running application
How well the codebase ages
Libraries, hosting, docs and hiring
How many kinds of product it suits
How it scales
One Nginx container handles a lot of traffic on modest hardware; scaling out means several instances behind a cloud load balancer, at which point an orchestrator's ingress or gateway layer often takes over.
- Starting outMVP and first users
- One `nginx` container on a VM proxying to an app container on the same Compose network, with certbot-managed certificates mounted read-only.
- GrowingReal traffic, a few engineers
- Nginx fronting several app replicas through an `upstream` block, with `proxy_cache` for hot responses, `limit_req` rate limits and config baked into a versioned image.
- LargeHeavy traffic or data
- Several Nginx instances on separate hosts behind a cloud load balancer, config rolled out by CI or Ansible, and metrics exported from the stub_status endpoint to Prometheus.
- EnterpriseMany teams and regions
- Usually replaced by a managed load balancer plus a Kubernetes Gateway API or ingress implementation, or by NGINX Plus or another proxy with dynamic upstream APIs and central management.
Where it fits
Common projects, from best fit to worst.
TLS reverse proxy for a containerised app
Terminates HTTPS, sets forwarding headers and proxies to one or more app containers on the same Docker network.
Great fit
Static SPA hosting in a multi-stage image
Build the frontend in a Node stage, copy the output into an `nginx:alpine` stage and serve it with a `try_files $uri /index.html` fallback.
Great fit
Caching and rate-limiting layer
`proxy_cache` absorbs repeated reads and `limit_req` throttles abusive clients before they reach slower app servers.
Good fit
Routing for frequently changing containers
Without service discovery each new or rescheduled service needs config edits and reloads; Traefik or a Kubernetes ingress layer handles this automatically.
Poor fit
Alternatives
Similar stacks, and when you would choose them instead.
- Kubernetes + Docker
Pick it when routing spans many services and nodes; Gateway API or an ingress controller replaces hand-maintained upstream blocks.
CompareNginx + Docker with Kubernetes + Docker - Jamstack
Pick it for static or pre-rendered sites, where a managed CDN host handles TLS, caching and global distribution without running a proxy.
CompareNginx + Docker with Jamstack - LAMP
Pick it for PHP applications served by Apache httpd, where per-directory `.htaccess` rules and mod_php or PHP-FPM integration matter.
CompareNginx + Docker with LAMP
Sources
Reviewed on November 19, 2026 against the documentation below. Found something out of date? Suggest a correction. Read our methodology.
- Nginx documentation
Official Nginx docs.
- Nginx proxy module
Reference for proxy_pass, headers, buffering and proxy_cache.
- Official Nginx Docker image
Image variants, config template support and logging behaviour.
Related stacks
Stacks that share technologies with Nginx + Docker.
Docker Compose + PostgreSQL
Docker Compose runs PostgreSQL from the official image alongside application containers, the standard local development setup and a common single-server deployment.
- Docker
- PostgreSQL
Learning: Easy
Kubernetes + Helm
Helm charts package Kubernetes manifests as versioned, parameterised releases that can be installed, upgraded and rolled back.
- Kubernetes
- Helm
Learning: Hard
Prometheus + Grafana
Prometheus scrapes and stores time-series metrics and evaluates alert rules; Grafana queries it with PromQL for dashboards, the standard open-source metrics pairing.
- Prometheus
- Grafana
Learning: Moderate