Reverse proxy and service exposure
Worked example
This is an offline lesson. Data are fictional and Docker commands are unexecuted. Any optional execution requires an authorized disposable VM, a verified context, synthetic data, restricted access and no external transmission. Do not collect secrets or private output. Use only the fictional worksheet for this exercise. Before a separately authorized read-only server query, verify the effective endpoint including environment overrides, project or cluster identity, and access scope. Never deploy the fragments, use real credentials or transmit private inspection output.
Illustrative network topology (not a deployable file):client -> proxy:8443 -> app:8080 -> db:5432edge network: proxy + appbackend network: app + dbhost port plan: 127.0.0.1:18443 -> proxy:8443app/db: no host port mappingsNGINX location fragment (inside a reviewed server block):location / { proxy_pass http://app:8080; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_connect_timeout 3s; proxy_read_timeout 15s;}The service name app resolves on the shared edge network; db is not a member of that network. The example overwrites forwarding metadata at a single trusted edge instead of accepting arbitrary client claims. The application must trust forwarding headers only from its verified proxy, validate allowed hosts and enforce its own authorization. If additional trusted proxies exist, design a specific trust chain. No host mapping for app or db reduces direct exposure, but does not make the host or Docker administrator untrusted. A backend connection failure may yield 502; a timeout may yield 504. Inspect proxy and application evidence before modifying timeouts. Review DNS re-resolution or controlled proxy reload when replacing upstream containers. The fragment is not a complete TLS or NGINX configuration. The read timeout limits inactivity between successive upstream reads, not the total request duration. The proposed loopback binding is not evidence of isolation; check Engine version and actual reachability in any authorized test. Verify backend reachability and application authorization separately.
Common mistake
Do not publish the database port merely to make the proxy work. The proxy needs the app endpoint on its shared network, not access to the database.
Manual practice
Draw the two network memberships. Describe a test for permitted proxy-to-app traffic and a negative check for unintended host exposure; explain how a 502 differs from a successful app response.
Worksheet: lab-fixtures/docker-production-deployment/02-reverse-proxy/scenario.txt.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Reverse proxy and service exposure — Knowledge check
Interpret production deployment evidence and make a safe operational decision.
Which service needs a published port in this design?
Which header policy is appropriate for a single trusted edge?
What should a 502 prompt you to check?