Skip to content

Commit 148f72f

Browse files
committed
feat(networking): add checkpoint 12 reverse proxy and traffic routing lab
1 parent 22dad65 commit 148f72f

2 files changed

Lines changed: 276 additions & 0 deletions

File tree

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
# Checkpoint 12 — Reverse Proxy & Traffic Routing with Nginx
2+
3+
## Objective
4+
5+
Understand how reverse proxies work in modern infrastructure by using Nginx to route incoming requests to multiple Docker containers.
6+
7+
This checkpoint demonstrates how a single public endpoint can forward requests to the correct internal service.
8+
9+
---
10+
11+
# What We Built
12+
13+
We created a small multi-container application composed of:
14+
15+
- Frontend container (Nginx static site)
16+
- Backend container (Node.js API)
17+
- Nginx reverse proxy container
18+
- Docker Compose network
19+
20+
Users interact with only one public port:
21+
22+
http://localhost:8080
23+
24+
Nginx receives the request and decides where to send it.
25+
26+
---
27+
28+
# Architecture
29+
30+
```text
31+
Browser
32+
33+
34+
localhost:8080
35+
36+
37+
┌─────────────────────┐
38+
│ NGINX │
39+
│ Reverse Proxy │
40+
└─────────┬───────────┘
41+
42+
┌─────┴─────┐
43+
│ │
44+
▼ ▼
45+
46+
Frontend Backend
47+
(Container) (Container)
48+
49+
"/" "/api"
50+
51+
Port 80 Port 4000
52+
```
53+
54+
---
55+
56+
# Request Flow
57+
58+
### Frontend Request
59+
60+
```text
61+
GET /
62+
```
63+
64+
Flow:
65+
66+
```text
67+
Browser
68+
69+
localhost:8080
70+
71+
Nginx
72+
73+
frontend container
74+
```
75+
76+
---
77+
78+
### Backend Request
79+
80+
```text
81+
GET /api
82+
```
83+
84+
Flow:
85+
86+
```text
87+
Browser
88+
89+
localhost:8080/api
90+
91+
Nginx
92+
93+
backend container
94+
```
95+
96+
---
97+
98+
# Key Concepts Learned
99+
100+
## Reverse Proxy
101+
102+
A reverse proxy sits between users and backend services.
103+
104+
Responsibilities:
105+
106+
- Receives requests
107+
- Routes traffic
108+
- Hides internal services
109+
- Centralizes access
110+
- Improves scalability
111+
112+
---
113+
114+
## Docker Networking
115+
116+
Docker Compose automatically created an isolated network for all containers.
117+
118+
Containers communicate using service names:
119+
120+
```nginx
121+
proxy_pass http://backend:4000;
122+
```
123+
124+
instead of:
125+
126+
```text
127+
localhost:4000
128+
```
129+
130+
---
131+
132+
## Why Reverse Proxies Matter
133+
134+
Modern applications rarely expose every service directly.
135+
136+
Instead:
137+
138+
```text
139+
Internet
140+
141+
Load Balancer
142+
143+
Nginx
144+
145+
Containers
146+
```
147+
148+
This architecture is used by:
149+
150+
- Netflix
151+
- YouTube
152+
- Spotify
153+
- Amazon
154+
- Vercel
155+
- AWS
156+
- Kubernetes clusters
157+
158+
---
159+
160+
# Commands Used
161+
162+
Start containers:
163+
164+
```bash
165+
docker compose up --build
166+
```
167+
168+
Stop containers:
169+
170+
```bash
171+
docker compose down
172+
```
173+
174+
View running containers:
175+
176+
```bash
177+
docker ps
178+
```
179+
180+
View logs:
181+
182+
```bash
183+
docker logs reverse-proxy-lab-nginx-1
184+
185+
docker logs reverse-proxy-lab-backend-1
186+
187+
docker logs reverse-proxy-lab-frontend-1
188+
```
189+
190+
---
191+
192+
# Nginx Routing Rules
193+
194+
```nginx
195+
location / {
196+
proxy_pass http://frontend;
197+
}
198+
199+
location /api {
200+
proxy_pass http://backend:4000;
201+
}
202+
```
203+
204+
---
205+
206+
# Verification
207+
208+
The system successfully:
209+
210+
✅ Built all Docker images
211+
212+
✅ Created the Docker network
213+
214+
✅ Started frontend, backend, and Nginx containers
215+
216+
✅ Routed requests to `/`
217+
218+
✅ Routed requests to `/api`
219+
220+
✅ Verified communication between containers
221+
222+
---
223+
224+
# Important Discoveries
225+
226+
- Users do not talk directly to containers.
227+
- Nginx decides where traffic goes.
228+
- Docker provides networking between containers.
229+
- URL paths determine routing behavior.
230+
- Reverse proxies are foundational to cloud systems.
231+
- Kubernetes Ingress works using similar concepts.
232+
233+
---
234+
235+
# Mental Models
236+
237+
| Component | Mental Model |
238+
| ---------------- | ------------------ |
239+
| Docker Container | House |
240+
| Docker Network | Neighborhood |
241+
| Nginx | Receptionist |
242+
| Reverse Proxy | Traffic Controller |
243+
| URL Path | Destination |
244+
| Browser | Visitor |
245+
246+
---
247+
248+
# Reflection
249+
250+
Before this checkpoint, containers felt isolated.
251+
252+
After this checkpoint, I understood that:
253+
254+
- Containers communicate through Docker networks.
255+
- Nginx routes requests using rules.
256+
- One public endpoint can manage multiple services.
257+
- Reverse proxies are essential in production systems.
258+
259+
This checkpoint bridges Docker fundamentals and future topics such as:
260+
261+
- Load balancing
262+
- Kubernetes Services
263+
- Kubernetes Ingress
264+
- Cloud infrastructure
265+
- Scalable systems
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server {
2+
listen 80;
3+
4+
location / {
5+
proxy_pass http://frontend:80;
6+
}
7+
8+
location /api {
9+
proxy_pass http://backend:4000;
10+
}
11+
}

0 commit comments

Comments
 (0)