Flask · Lesson 15 of 15
Production: Gunicorn, Nginx and Docker
A release checklist: workers, reverse proxy, env vars and health checks.
- Advanced
- 16 min read
- 3 objectives
Before this lessonLesson 14: Migrations and Schema Changes
What you will learn
- Run gunicorn
- Terminate TLS at Nginx
- Health-check the app
Your Progress
0 of 15 lessons 0%
- Lessons0 / 15
- Completed0
- Est. time left~ 4 hours
Create a free account to keep your progress on every device.
The development server is single-process and not hardened. Production is gunicorn, a reverse proxy, and config from the environment.
Gunicorn
gunicorn -w 4 -b 0.0.0.0:8000 --access-logfile - --timeout 30 wsgi:app# wsgi.py
from myapp import create_app
from myapp.config import ProdConfig
app = create_app(ProdConfig)Docker
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENV FLASK_CONFIG=myapp.config.ProdConfig
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:8000", "wsgi:app"]Release checklist
DEBUGfalse, strongSECRET_KEYfrom the environment.- HTTPS at the proxy;
PREFERRED_URL_SCHEME = "https"andProxyFixif you are behind one. - Migrate on release, then start workers.
/healththat checks the database for the load balancer.
# Write your solution here
