
Below is a detailed, production-ready guide for How to Deploy Django 6 on Ubuntu VPS.
What is Django?
Django is a high-level, open-source web framework for Python that enables developers to build secure, scalable, database-driven websites and APIs quickly. It follows the ModelโViewโTemplate (MVT) architectural pattern and emphasizes rapid development, clean design, and robust security.
โญ Key Features of Django
-
๐ง Batteries-Included Framework
Django comes with a huge collection of built-in tools so you donโt have to reinvent common web development components. Included out of the box:
- Authentication & user management
- Admin dashboard (auto-generated!)
- ORM (Object-Relational Mapper)
- Routing system
- Template engine
- Security protections
- Form handling
- Sessions, caching, middleware, etc.
Djangoโs philosophy: โDo the right things automatically.โ
-
๐ Excellent Security
Django protects against many common attacks by default, including:
- SQL injection
- XSS (cross-site scripting)
- CSRF (cross-site request forgery)
- Clickjacking
- Host header attacks
Itโs considered one of the most secure web frameworks available today.
-
๐ Fast Development
Django was originally created to help newsrooms build applications quickly. Its strong emphasis on convention-over-configuration and built-in tools makes it extremely fast to develop with.
-
๐งฑ Djangoโs MVT Architecture (Model-View-Template)
-
Model
Defines data structure and database relations (via the ORM).
-
View
Handles business logic and returns responses (HTML, JSON, etc.).
-
Template
The UI layer. Defines how data is presented.
Itโs similar to MVC, just with Djangoโs twist.
-
-
๐ Database Flexibility
Django ships with first-class support for:
- PostgreSQL
- MySQL
- MariaDB
- SQLite
- Oracle
You write Python code โ Django ORM converts it to SQL โ database executes it.
-
๐ Scalable & Production-Ready
Used by companies like:
- Spotify
- Disqus
- Mozilla
Django features strong caching, pluggable apps, middleware, and modular designโmaking it suitable for both startups and massive, high-traffic services.
-
๐ Ecosystem & Community
Django has a massive ecosystem of reusable components (“Django apps”) for:
- APIs (Django REST Framework)
- Authentication & OAuth
- eCommerce
- CMS systems
- Payment gateways
- Background jobs (Celery)
Anything you need can usually be installed instantly.
๐ฆ Common Use Cases
- Web applications
- SaaS platforms
- Content management systems
- REST APIs & backends for mobile apps
- E-commerce
- Social platforms
- Machine-learning dashboards
- CRMs, ERPs, internal tools
๐งพ Summary
Django is a Python-based web framework designed to help developers build secure, scalable, database-powered applications quickly, using clean code and industry best practices.
This guide follows modern best-practices and includes Gunicorn, Nginx, PostgreSQL, Python 3.12+ venv, systemd services, TLS/HTTPS with Certbot, and Django 6 production settings.

๐ How to Deploy Django 6 on Ubuntu VPS
Works for: Ubuntu 22.04 / Ubuntu 24.04
Stack: Django 6 + Gunicorn + Nginx + PostgreSQL (optional) + Certbot SSL
Prereqs: Root or sudo access, domain name pointed to the server
-
Update Your Server
sudo apt update && sudo apt upgrade -y sudo apt install -y python3 python3-venv python3-pip git ufw
-
(Optional) Install PostgreSQL for Production
sudo apt install -y postgresql postgresql-contrib libpq-dev
Create DB + user:
sudo -u postgres psql CREATE DATABASE django_prod; CREATE USER django_user WITH PASSWORD 'STRONGPASSWORD'; ALTER ROLE django_user SET client_encoding TO 'utf8'; ALTER ROLE django_user SET default_transaction_isolation TO 'read committed'; ALTER ROLE django_user SET timezone TO 'UTC'; GRANT ALL PRIVILEGES ON DATABASE django_prod TO django_user; \q
-
Choose Deployment Directory
mkdir -p ~/apps/django_project cd ~/apps/django_project
Clone your project:
git clone https://github.com/your/repo.git .
-
Create Python Virtual Environment (Python 3.12+ recommended)
python3 -m venv venv source venv/bin/activate
Upgrade tools:
pip install --upgrade pip wheel setuptools
Install project dependencies:
pip install -r requirements.txt
If first install, ensure these are included:
pip install gunicorn psycopg[binary]
-
Configure Django for Production
Edit
settings.py:Allowed hosts:
ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com', 'IP_ADDRESS']
Static files:
STATIC_ROOT = BASE_DIR / "staticfiles"
Add secure settings:
CSRF_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True SECURE_SSL_REDIRECT = True # enable after Certbot installed
-
Collect Static Files & Run DB Migrations
source venv/bin/activate python manage.py migrate python manage.py collectstatic --noinput
-
Test Gunicorn Manually
Inside project root:
gunicorn --bind 0.0.0.0:8000 projectname.wsgi
If it works โ Ctrl+C.
-
Create systemd Service for Gunicorn
Create:
sudo nano /etc/systemd/system/gunicorn.service
Paste:
[Unit] Description=Gunicorn daemon for Django 6 After=network.target [Service] User=ubuntu Group=www-data WorkingDirectory=/home/ubuntu/apps/django_project Environment="PATH=/home/ubuntu/apps/django_project/venv/bin" ExecStart=/home/ubuntu/apps/django_project/venv/bin/gunicorn \ --workers 3 \ --bind unix:/home/ubuntu/apps/django_project/gunicorn.sock \ projectname.wsgi:application Restart=always [Install] WantedBy=multi-user.target
Enable:
sudo systemctl daemon-reload sudo systemctl enable --now gunicorn sudo systemctl status gunicorn
-
Install & Configure Nginx Reverse Proxy
sudo apt install -y nginx
Create site config:
sudo nano /etc/nginx/sites-available/django
Paste:
server { listen 80; server_name yourdomain.com www.yourdomain.com; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { alias /home/ubuntu/apps/django_project/staticfiles/; } location / { include proxy_params; proxy_pass http://unix:/home/ubuntu/apps/django_project/gunicorn.sock; } }Enable site:
sudo ln -s /etc/nginx/sites-available/django /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx
-
Configure Firewall
sudo ufw allow OpenSSH sudo ufw allow 'Nginx Full' sudo ufw enable
-
Enable HTTPS (Letโs Encrypt TLS)
sudo apt install -y certbot python3-certbot-nginx sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Auto-renew:
sudo systemctl status certbot.timer
After SSL is installed, you may enable:
SECURE_SSL_REDIRECT = True
-
Supervisor for Background Workers (optional)
For Celery:
sudo apt install -y supervisor
Create file
/etc/supervisor/conf.d/celery.conf:[program:celery] command=/home/ubuntu/apps/django_project/venv/bin/celery -A projectname worker --loglevel=INFO directory=/home/ubuntu/apps/django_project user=ubuntu autostart=true autorestart=true stopasgroup=true killasgroup=true stderr_logfile=/var/log/celery.err.log stdout_logfile=/var/log/celery.out.log
sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start celery
-
Useful Commands
Restart Gunicorn:
sudo systemctl restart gunicorn
View logs:
journalctl -u gunicorn -f
Restart Nginx:
sudo systemctl restart nginx
-
Directory Structure (Final)
/home/ubuntu/apps/django_project/ โโโ venv/ โโโ projectname/ โโโ manage.py โโโ gunicorn.sock โโโ staticfiles/
-
Hardening for Production
Recommended security additions:
- Use
.envfile with django-environ - Rotate SECRET_KEY regularly
- Enable HSTS:
SECURE_HSTS_SECONDS = 31536000 SECURE_HSTS_INCLUDE_SUBDOMAINS = True SECURE_HSTS_PRELOAD = True
- Disable admin on
/admin/or restrict via IP - Use Cloudflare or similar WAF
- Use
Summary (TL;DR)
- Create venv โ install Django + Gunicorn
- Configure PostgreSQL (optional)
- Run migrations + collectstatic
- Create Gunicorn
systemdservice - Configure Nginx reverse proxy
- Enable HTTPS via Certbot
- Harden security + optimize
Your Django 6 app is now running in production.

Conclusion
You now know how to deploy Django 6 on Ubuntu VPS.








