10 min read
How to Deploy a Flask App: Four Paths Compared
Key takeaways
- Deploy a Flask app via Gunicorn and Nginx on a VPS, Docker, a free tier, or a managed PaaS with git push, depending on traffic, budget, and payment options.
- Pin dependencies with pip freeze, serve with Gunicorn instead of the dev server, and move secrets to environment variables before any deployment.
- Payment access matters as much as price: many free tiers and PaaS providers require a USD-billing card, while some PaaS options accept MTN or Airtel mobile money.
- For a small Flask app on a 1 GB VPS, start Gunicorn with --workers 3 --threads 2, --timeout 60, and --max-requests 500 with jitter.
- Serve a Flask and React app together by having Nginx serve the built React files and proxy /api/ routes to Gunicorn, avoiding CORS entirely.
To deploy a Flask app, pick one of four paths: Gunicorn and Nginx on a VPS, Docker with Nginx, a free tier, or a managed PaaS with git push. Your choice depends on your traffic, your budget, and whether you can pay with a card that bills in USD or need mobile money. This guide gives you a short framework to pick the right path, then copy-paste commands for each one.
Which deployment path is right for your Flask app?
Pick based on two questions: how much infrastructure you want to manage, and how you can actually pay. If you can rent a VPS with a local card or mobile money and enjoy server work, Gunicorn and Nginx is the cheapest path. If your app has extra services or teammates, Docker saves you from config drift. If you want git push and nothing else, a managed PaaS wins.
Decision table: four paths compared
| Path | Setup effort | Monthly cost shape | Payment friction | Best for |
|---|---|---|---|---|
| VPS + Gunicorn/Nginx | High | Flat, cheap | Low if local card works | Side projects, learning |
| Docker + Nginx | Medium-high | Flat, cheap | Same as VPS | Multi-service apps |
| Free tier | Low | $0 until limits | USD card often needed to upgrade | Demos, prototypes |
| Managed PaaS | Low | Scales with usage | Varies; some accept mobile money | First SaaS, no-ops deploys |
The payment question most guides skip
Free tiers on Render or Railway look free until you need a paid plan, and most bill in USD on cards many Kenyan and Ugandan developers don't hold. Treat payment access as a first-class criterion, equal to price. Worker counts and tuning for Gunicorn are documented in the Gunicorn deployment docs if you go the VPS route. For a managed path with git push, see our walkthrough on how to deploy Node.js with git push — the same flow applies to Flask apps.
How do you prepare a Flask app for production?
Before any deployment path works, three things must change in your app: pinned dependencies, a production server, and secrets moved out of the code.
Pin dependencies with a requirements file
Run pip freeze > requirements.txt so the exact versions you tested locally are what the server installs. Unpinned versions are the most common reason a side project works on your laptop and breaks on deploy. Commit the file to GitHub so a git push to deploy can rebuild your app identically every time.
Serve with Gunicorn, not the dev server
Flask's built-in server is single-threaded and meant for development only. Install Gunicorn and run it with gunicorn -w 2 app:app, where app is your module and Flask instance. Every path in this guide, from a plain VPS to a managed PaaS like Omeganodes, expects Gunicorn (or another WSGI server) as the entry point.
Environment variables and secrets
Move your SECRET_KEY, database URLs, and API keys into environment variables. Read them with os.environ.get("SECRET_KEY") and never commit them to GitHub. Each host sets these differently: a .env file on a VPS, a config panel on a PaaS. If you want the deploy step itself handled for you, see how push-to-deploy works on Omeganodes.
How do you deploy a Flask app using Gunicorn and Nginx on a VPS?
You need three pieces: Gunicorn serving your Flask app, Nginx forwarding traffic to it, and Certbot for HTTPS. The Flask docs on deploying to production cover the same ground, but here are the commands.
Install Gunicorn and create a systemd service
pip install gunicorn
Create /etc/systemd/system/myapp.service:
[Unit]
Description=My Flask app
After=network.target
[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/myapp
ExecStart=/home/ubuntu/myapp/venv/bin/gunicorn -w 2 -b 127.0.0.1:8000 app:app
Restart=always
[Install]
WantedBy=multi-user.target
Then run sudo systemctl enable --now myapp. This is the piece a managed PaaS does for you. If your VPS bill is due and you have no card that works, the service stops. This is why payment matters as much as commands: providers like Render bill in USD, so developers paying with MTN Mobile Money or Airtel Money often cannot even start this path, while a PaaS such as Omeganodes accepts mobile money directly. If your card works and you are comfortable with SSH, the VPS path is the cheapest way to run a Flask app long-term.
Configure Nginx as a reverse proxy
Install Nginx, then create /etc/nginx/sites-available/myapp:
server {
listen 80;
server_name myapp.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
}
}
Enable it with sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/ and reload Nginx.
Add HTTPS with Certbot
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d myapp.com
Certbot renews automatically. One honest limitation: you are now on call for OS updates, certificate renewals, and restarts, which is exactly the work the quotes above say they never want to think about again.
How do you deploy a Flask app with Docker and Nginx?
Docker wraps your Flask app, Gunicorn, and dependencies into one image, so the container you test locally is the container you ship. Pair it with Nginx as a reverse proxy and you get a repeatable setup that survives server changes. The cost: you now maintain a Dockerfile and compose file instead of just running git push.
A minimal Dockerfile for Flask
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt gunicorn
COPY . .
CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"]
Build and run it with:
docker build -t flask-app .
docker run -p 8000:8000 flask-app
Pin your Python version and use a slim base image to keep the build small. Never run the Flask development server in the container; Gunicorn is the process that faces traffic.
docker-compose with Gunicorn and Nginx
services:
web:
build: .
expose:
- "8000"
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- web
Nginx proxies port 80 to the Flask container on port 8000 and terminates HTTPS with your certificates. If this stack is more YAML than you want to own, a PaaS that runs the same Gunicorn setup for you, like Omeganodes, removes the Dockerfile entirely.
Can you deploy a Flask app on a free tier?
Yes. Render, Railway, and Fly.io all let you deploy a Flask app without paying, and free tiers work well for demos, hackathon projects, and side projects with light traffic.
What free tiers typically restrict
Most free tiers limit three things: compute (the app sleeps after inactivity, so the first request after a pause takes seconds), resources (small RAM, no persistent disk), and custom domains or HTTPS options on the lowest plan. Render's free web services spin down when idle, for example. If your app needs a background worker, a database with real storage, or uptime guarantees, a free tier will frustrate you. Payment is also a hidden limit: upgrading usually requires a card that bills in USD, which many Kenyan and Ugandan developers do not have.
When a free tier is enough
A free tier is enough when your app is a portfolio piece, a demo for clients, or an MVP validating demand. Once you have real users, move to a paid plan or a PaaS with regional pricing, like Omeganodes, which accepts MTN and Airtel mobile money. Behind the scenes, every free-tier platform still runs your Flask app under Gunicorn (or a similar server) behind a reverse proxy, the pattern documented in the Nginx official documentation on reverse proxy configuration.
How do you deploy a Flask app on a managed PaaS with git push?
A managed PaaS runs your Flask app on servers someone else maintains. You connect a GitHub repo, push a commit, and the platform builds and restarts the app, usually with automatic HTTPS and a custom domain. No Kubernetes, no YAML, no SSH sessions.
Git push to deploy, step by step
- Push your Flask repo to GitHub with a
requirements.txtand aProcfileor start command (for example,gunicorn app:app). - Create the app on the platform and connect the repo.
- Set environment variables like
SECRET_KEYand database URLs in the dashboard. - Add a custom domain, then
git push. Every push after that redeploys automatically.
This is the closest thing to the Heroku workflow readers on Hacker News describe as "configure once and operate forever": you never think about infrastructure beyond initial setup.
Paying without an international card
Most PaaS pricing assumes a USD-billing card, which is exactly what many Kenyan and Ugandan developers lack. Render, Railway, and Fly.io all expect card payments. Omeganodes is built for this gap: EU servers, automatic HTTPS, fair regional pricing worldwide, and MTN Mobile Money and Airtel Money support, so you can pay from a phone without a card. Ziploy and Talksasa Cloud are regional alternatives worth checking against the same criteria.
One honest limitation: a managed PaaS costs more than a $5 VPS, and if you outgrow it, you may eventually move to the Docker or VPS paths above.
How do you deploy a Flask and React app together?
Treat them as two artifacts in one deployment: Flask serves the API, Nginx serves the built React files, and one domain fronts both. That means one HTTPS certificate, one bill, and no CORS setup.
Build the React app, serve it from Nginx
Run npm run build locally or in CI, then copy the build/ or dist/ folder to your server. Point Nginx's root at it and add try_files $uri /index.html; so client-side routing works on refresh. Get your certificate with Certbot, which automates Let's Encrypt HTTPS setup.
Proxy API routes to Flask
Add a location block so /api/ passes to Gunicorn on localhost, e.g. proxy_pass http://127.0.0.1:8000;. Your React code then calls /api/... with no cross-origin requests. On a PaaS like Omeganodes, deploy the Flask repo as usual and host the static React build on the same domain's CDN path instead.
How do you keep a production Flask app running?
Workers, timeouts and restarts
Gunicorn defaults to one worker, which will choke on the first slow request. Start with --workers 3 --threads 2 for a small Flask app on a 1 GB VPS, and set --timeout 60 so a hanging request gets killed instead of wedging the worker. Add --max-requests 500 --max-requests-jitter 50 to recycle workers and clear slow memory leaks.
Run Gunicorn under systemd with Restart=always so a crash means a restart, not a dead site. If your process manager offers health checks, point one at a cheap /health route.
Logs, monitoring and rollbacks
Send stdout to journald (journalctl -u myapp -f) or a file you rotate, and log exceptions with a traceback, not just a message. Watch p95 response time and memory; when memory climbs steadily across restarts, you have a leak worth chasing. Deploy with a tagged release, keep the previous one deployable, and roll back by redeploying the last tag. On a PaaS like Omeganodes or Render, git push gives you this loop by default; on a VPS you build it once with a short deploy script.
FAQ
How much does it cost to deploy a Flask app per month?
A small VPS runs about $5 a month flat, the cheapest long-term option if you handle updates yourself. Free tiers cost $0 until you hit limits, then paid plans usually start around $5-10 billed in USD. A managed PaaS costs more than a VPS but scales with usage, and some offer regional pricing.
Can I deploy a Flask app without a credit card, paying with MTN Mobile Money or Airtel Money?
Yes, but only with some providers. Render, Railway, and Fly.io expect a card that bills in USD, which many Kenyan and Ugandan developers don't hold. Omeganodes accepts MTN Mobile Money and Airtel Money directly, so you can pay from a phone. Ziploy and Talksasa Cloud are regional alternatives worth checking against the same payment criteria.
Do I need Docker to deploy a Flask app on a production server?
No. Docker helps when your app has multiple services or teammates who need identical environments, because the container you test locally is the container you ship. For a single Flask app, Gunicorn and Nginx on a VPS works fine without any Dockerfile, and a managed PaaS removes the need entirely by building from your repo on every push.
How many Gunicorn workers should I run for a small Flask app?
Start with three workers and two threads for a small app on a 1 GB VPS, using --workers 3 --threads 2. Set --timeout 60 so a hanging request gets killed, and add --max-requests 500 --max-requests-jitter 50 to recycle workers and clear slow memory leaks. The default single worker will choke on the first slow request.
Is Heroku still an option for deploying Flask apps after the 2026 sustaining-mode announcement?
Heroku's workflow remains the model for push-to-deploy, but the announcement means the platform gets minimal maintenance going forward, so it's a poor home for a new Flask app. The same git push flow exists on managed PaaS providers: connect your repo, set environment variables in a dashboard, add a domain, and every push redeploys automatically.
Deploy at the speed of Africa
World-class hosting, open to every developer, wherever you build and however you pay. Start free in a couple of minutes — no credit card, no lock-in.