This website runs on one small rented Linux server. No Kubernetes, no managed platform, no monthly bill that grows every time traffic spikes. Just Django, Gunicorn, Nginx, systemd and a free HTTPS certificate. It has been quietly serving pages, a chatbot and a contact form for months, and the whole setup fits in four short files.
In this post I walk through exactly how it works, step by step, so you can put your own Django app online the same way. I also share the mistakes that cost me time, because those are the parts tutorials usually skip.
The big picture
A request to the site travels through four layers, and each one has a single job.
Nginx faces the internet. It handles HTTPS, serves CSS, JavaScript and images straight from disk, and passes everything else to the app.
Gunicorn runs the Django code. It keeps a few worker processes ready so pages render fast.
systemd keeps Gunicorn alive. If the app crashes or the server reboots, systemd starts it again on its own.
Let's Encrypt gives a free HTTPS certificate, and certbot renews it automatically before it expires.
Nginx and Gunicorn talk through a Unix socket file instead of a network port. It is slightly faster, and the app is never reachable from outside except through Nginx.
Step 1: Prepare the server
I use Ubuntu 24.04 LTS. Long-term support releases get security updates for years, which matters more than having the newest packages. Start by updating and installing the basics:
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3-venv python3-pip nginx git certbot python3-certbot-nginx
Create a separate Linux user for the app instead of running it as root. If the app ever has a security bug, an attacker gets a limited account, not the whole machine:
sudo adduser --system --group --home /var/www/myapp app
Step 2: Get the code and a virtual environment
Clone the project and give it its own Python environment, so its packages never clash with the system ones:
cd /var/www
sudo git clone https://github.com/you/myapp.git
sudo chown -R app:app /var/www/myapp
cd /var/www/myapp
sudo -u app python3 -m venv venv
sudo -u app venv/bin/pip install -r requirements.txt gunicorn
Keep secrets out of the code. I put the secret key, debug flag and allowed hosts in a .env file on the server that is never committed to Git:
SECRET_KEY=change-me-to-a-long-random-string
DEBUG=False
ALLOWED_HOSTS=example.com,www.example.com
Load these values in settings.py, for example with the python-dotenv package, or add an EnvironmentFile= line to the systemd service in the next step. Then prepare the database and the static files:
sudo -u app venv/bin/python manage.py migrate
sudo -u app venv/bin/python manage.py collectstatic --noinput
sudo -u app venv/bin/python manage.py check --deploy
The last command is underrated. Django lists the security settings you forgot, like secure cookies and HSTS. Fix everything it reports before going live.
Step 3: Run Gunicorn with systemd
Create /etc/systemd/system/myapp.service:
[Unit]
Description=myapp (Gunicorn)
After=network.target
[Service]
User=app
Group=www-data
WorkingDirectory=/var/www/myapp
ExecStart=/var/www/myapp/venv/bin/gunicorn \
--workers 3 \
--bind unix:/run/myapp.sock \
--access-logfile /var/log/myapp-access.log \
--error-logfile /var/log/myapp-error.log \
config.wsgi:application
Restart=always
[Install]
WantedBy=multi-user.target
A common rule of thumb for workers is two per CPU core plus one, but on a small server three is a safe start. Turn it on:
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
sudo systemctl status myapp
Restart=always is the line that lets me sleep at night. If something crashes at 2 a.m., systemd brings it back within seconds.
Step 4: Put Nginx in front
Create /etc/nginx/sites-available/myapp:
server {
listen 80;
server_name example.com www.example.com;
location /static/ {
alias /var/www/myapp/staticfiles/;
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
location / {
proxy_pass http://unix:/run/myapp.sock;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable it and check the syntax before reloading. nginx -t has saved me from taking a site down more than once:
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
The one-year cache on static files is safe because Django's ManifestStaticFilesStorage adds a fingerprint to every file name, like style.5463684df179.css. When a file changes, its name changes, so browsers fetch the new one immediately while unchanged files load instantly from cache.
Step 5: Free HTTPS
Point your domain's DNS at the server, then let certbot do the rest:
sudo certbot --nginx -d example.com -d www.example.com
Certbot edits the Nginx file to add HTTPS and a redirect from HTTP, and installs a timer that renews the certificate automatically. You can confirm the timer exists with systemctl list-timers. While you are in the Nginx file, add a few security headers such as Strict-Transport-Security, X-Content-Type-Options and Referrer-Policy.
Step 6: A deploy routine you can trust
My deploys are deliberately boring. I push to GitHub from my laptop, then on the server:
cd /var/www/myapp
sudo -u app git pull --ff-only
sudo -u app venv/bin/pip install -r requirements.txt
sudo -u app venv/bin/python manage.py migrate
sudo -u app venv/bin/python manage.py collectstatic --noinput
sudo systemctl restart myapp
The --ff-only flag refuses to pull if the server has changes that are not on GitHub. Instead of quietly creating a merge on production, it stops and tells you.
Step 7: Backups that run while you sleep
A server you cannot rebuild is a server you are afraid to touch. Two habits keep me calm.
Before any risky change, I copy the database. With SQLite, use its built-in backup feature rather than copying the file, because it gives a consistent copy even while the site is running:
venv/bin/python -c "import sqlite3; s=sqlite3.connect('db.sqlite3'); d=sqlite3.connect('backups/db-before-change.sqlite3'); s.backup(d)"
Every night at 3 a.m., a cron job exports the site's content to a JSON file and pushes it to GitHub if anything changed. Code and content both live in Git, so I could rebuild the whole site on a new server in under an hour.
One rule matters here: never push visitors' personal data to Git. My backup excludes visitor logs and messages from the contact form. Those stay only on the server.
Mistakes that cost me time
These are real ones from running this site.
Changing CSS without running collectstatic. Nginx serves static files from the collected folder, so my change simply did not appear. Now collectstatic is part of every deploy, even when I think I only touched a template.
Forgetting the nightly backup when pushing. The server commits a backup every night, so pushing from my laptop without pulling first gets rejected. The fix is a habit: always git pull before git push.
Restarting the wrong thing. This server also hosts other services, so I restart only my app's own service, never Nginx or the whole machine, unless I truly need to. A reload of Nginx is enough for configuration changes and drops no connections.
Contact form messages that went nowhere. The form looked fine and showed no error, but the view never saved anything. Test every form end to end on the live site by sending yourself a real message.
Is this enough for production?
For a portfolio, a blog, an internal tool or a small business app, yes. One small server like this can comfortably handle thousands of visitors a day. When you outgrow it, the same pieces scale up: switch SQLite to PostgreSQL, add more Gunicorn workers, then move to a bigger server. You never have to throw the setup away.
The best part is that you understand every layer. When something breaks, you know exactly where to look: the Nginx error log, the Gunicorn log, or systemctl status. That understanding is worth more than any one-click platform.
If you get stuck deploying your own app, send me a message through the contact form on this site. I am happy to help.