Proxies and load balancing: one front door
Trace forward and reverse proxy paths, route HTTP through Nginx, and understand health checks and layer 4 versus layer 7 balancing.
By the end of this lesson you'll be able to
0 of 4 completeVerified lab: two temporary nginx:alpine containers ran on a private Docker network. The front Nginx
proxied a request to the backend and returned its page. The output is real; the script removes both containers
and the network on exit.
Cloud lab: none. No load balancer or cloud resource was created.
Before proxies, each application often handled public traffic directly. That made certificates, routing, and traffic spikes every app team's separate problem. A proxy creates one managed entry point and opens a second connection to the chosen backend. In this lesson, you will follow those two connections, read a real Nginx proxy rule, and compare load-balancing decisions.
Forward and reverse proxies
A forward proxy acts for clients, often to apply outbound access policy or share an egress point. A reverse proxy acts for a service. Clients connect to it, and it chooses an application server. From the client, both may look like an ordinary server; the difference is who owns and configures the proxy.
Use a forward proxy when you manage client egress. Use a reverse proxy for a service front door, TLS termination, or request routing. Neither makes the backend secure by itself. Keep backend ports private and define which headers the proxy forwards.
Nginx as a reverse proxy
Nginx receives the client connection, matches a location, and opens its own upstream connection. The backend
does not see the client's original TCP connection. Forward the original host or client address only when the app
needs it, and trust those headers only from your proxy.
server { listen 80; location / { proxy_pass http://backend:80; } }
This is the configuration used in the container lab. The real response was:
$ wget -qO- http://127.0.0.1/ (inside the proxy container) backend response $ nginx -T (selected directives) listen 80; proxy_pass http://backend:80;
wget -qO- http://127.0.0.1/ (inside the proxy container)wgetdownload a file
The command inspected the proxy container. Its temporary backend name mapped to the backend container's address.
In a production network, use stable service discovery and protect the upstream path.
Before reloading a changed config, validate it:
$ nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
This is the real check from the temporary proxy container.
L4 and L7 load balancing
A layer 4 balancer distributes TCP or UDP connections using addresses and ports. A layer 7 balancer can
route HTTP using the host, path, or headers. L4 works with many protocols and has less application awareness. L7
can route /api and /images differently, but must understand that protocol.
Choose the layer based on what the routing decision needs to inspect. A common mistake is assuming an L7 rule changes DNS or repairs the backend. It only routes the connection it receives.
Health checks
A health check asks whether a target should receive new traffic. A TCP check proves that a port accepted a connection. An HTTP check can test a readiness endpoint and status code. The check interval and failure threshold control how quickly a target leaves or returns to rotation.
Make the check reflect the service's ability to handle work. Do not make it depend on every optional dependency, or a harmless database hiccup may remove all targets. Do not check only a process that is alive but cannot serve requests. Nginx's open-source upstream checks are passive: real request failures influence target selection.
Trace a request through Nginx
Run the disposable two-container proxy lab. Inspect its proxy_pass rule and confirm that the response came from the backend. The script cleans up its containers and network.
backend response from the upstream through NginxReveal one safe solution
bash devops-academy-tools/networking-lab/09-capture.sh
Open the script to see the temporary backend, proxy config, and cleanup trap. The request is made to the proxy, not directly to the backend.
Try it yourself
0 of 4 steps doneRun each task in your own account or terminal, then tick it off.
Quick check
A reverse proxy receives a browser request and sends it to an application server. Who configured that proxy?
Official reading for this lesson
Or get every quiz answer right and it completes itself.
Something unclear, wrong or out of date in this lesson? Tell me, and I'll fix it.