Front It with Nginx and Compose
Reverse proxy and orchestrate the stack.
Front It with Nginx and Compose is a free Flask Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flask Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Add Nginx
Gunicorn runs your app, but Nginx sits in front as a reverse proxy. It handles the messy public-facing work so Gunicorn can focus on Python. 🛡️
What a Reverse Proxy Does
A reverse proxy receives every client request first, then forwards it to Gunicorn and relays the response back out.
Nginx Serves Static Files
Let Nginx serve your CSS, JS, and images directly. It is far faster at shipping static files than Python ever will be.
TLS Lives Here Too
Nginx is the natural place to terminate HTTPS. It handles certificates and encryption, leaving Gunicorn to speak plain HTTP internally.
The proxy_pass Directive
In your Nginx config, proxy_pass tells it where to send traffic. You point it at the Gunicorn container by name and port.
location / {
proxy_pass http://web:8000;
}Enter Docker Compose
Docker Compose runs multiple containers together from one YAML file. Perfect for an app container plus an Nginx container.
Define the Web Service
In compose, your Flask image becomes the web service. Compose builds it from your Dockerfile and names it for other containers to reach.
services:
web:
build: .Add the Nginx Service
Add an nginx service that uses the official image and mounts your config file. It will publish ports to the outside world.
nginx:
image: nginx:alpine
ports:
- "80:80"They Talk by Service Name
Compose puts both containers on one network. Nginx reaches Gunicorn at http://web:8000 using the service name as the host.
Control Startup Order
Use depends_on so Nginx starts after web. It does not wait for readiness, but it sets a sensible boot sequence.
depends_on:
- webBring the Stack Up
One command launches everything. docker compose up builds, networks, and starts both services as a single running stack.
docker compose up -d --buildQuick Check
What is Nginx doing in front of Gunicorn?
Recap
Nginx fronts Gunicorn, and Compose wires both into one stack you launch with a single command. You can now ship Flask to production. 🎉
Frequently asked questions
Is the “Front It with Nginx and Compose” lesson free?
Yes — the full text of “Front It with Nginx and Compose” is free to read here on the web, and the Flask Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flask Academy course, upgrade to CoddyKit PRO.
What will I learn in “Front It with Nginx and Compose”?
Reverse proxy and orchestrate the stack. You practise Flask Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Flask Academy?
No prior experience is required. Flask Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Front It with Nginx and Compose” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Flask Academy lesson?
Yes. Every Flask Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Why Not the Built-in Dev Server
- Run Flask Under Gunicorn
- Write a Production Dockerfile
- Front It with Nginx and Compose