...
🚀 how to deploy django 6 on ubuntu vps
Learn how to deploy django 6 on ubuntu vps!

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

  1. 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.”

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. Scalable & Production-Ready

    Used by companies like:

    • Instagram
    • Spotify
    • Disqus
    • Pinterest
    • Mozilla

    Django features strong caching, pluggable apps, middleware, and modular design—making it suitable for both startups and massive, high-traffic services.

  7. 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.

Launch 100% ssd ubuntu vps from $3. 19/mo!


Compare Ubuntu VPS Plans

KVM-SSD-1
KVM-SSD-8
KVM-SSD-16
KVM-SSD-32
CPU
1 Core
2 Cores
4 Cores
8 Cores
Memory
1 GB
8 GB
16 GB
32 GB
Storage
16 GB NVMe
128 GB NVMe
256 GB NVMe
512 GB NVMe
Bandwidth
1 TB
4 TB
8 TB
16 TB
Network
1 Gbps
1 Gbps
1 Gbps
1 Gbps
Delivery Time
⏱️ Instant
⏱️ Instant
⏱️ Instant
⏱️ Instant
Location
US/EU/APAC
US/EU/APAC
US/EU/APAC
US/EU/APAC
Price
$7.58*
$39.50*
$79.40*
$151.22*
KVM-SSD-1
$7.58*
CPU 1 Core
Memory 1 GB
Storage 16 GB NVMe
Bandwidth 1 TB
Network 1 Gbps
Delivery Time ⏱️ Instant
Location US/EU/APAC
KVM-SSD-8
$39.50*
CPU 2 Cores
Memory 8 GB
Storage 128 GB NVMe
Bandwidth 4 TB
Network 1 Gbps
Delivery Time ⏱️ Instant
Location US/EU/APAC
KVM-SSD-16
$79.40*
CPU 4 Cores
Memory 16 GB
Storage 256 GB NVMe
Bandwidth 8 TB
Network 1 Gbps
Delivery Time ⏱️ Instant
Location US/EU/APAC
KVM-SSD-32
$151.22*
CPU 8 Cores
Memory 32 GB
Storage 512 GB NVMe
Bandwidth 16 TB
Network 1 Gbps
Delivery Time ⏱️ Instant
Location US/EU/APAC

🚀 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

See Also: Deploy Hanko on Debian VPS

To deploy Django 6 on Ubuntu VPS, follow the steps outlined below:

  1. Update Your Server

    sudo apt update && sudo apt upgrade -y
    sudo apt install -y python3 python3-venv python3-pip git ufw
    
  2. (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
    
  3. Choose Deployment Directory

    mkdir -p ~/apps/django_project
    cd ~/apps/django_project
    

    Clone your project:

    git clone https://github.com/your/repo.git .
    
  4. 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]
    
  5. 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
    
  6. Collect Static Files & Run DB Migrations

    source venv/bin/activate
    python manage.py migrate
    python manage.py collectstatic --noinput
    
  7. Test Gunicorn Manually

    Inside project root:

    gunicorn --bind 0.0.0.0:8000 projectname.wsgi
    

    If it works → Ctrl+C.

  8. 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
    
  9. 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:

    See Also: Setup Video Streaming with Icecast on AzuraCast VPS (8 Step Quick-Start Guide)

    sudo ln -s /etc/nginx/sites-available/django /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl restart nginx
    
  10. Configure Firewall

    sudo ufw allow OpenSSH
    sudo ufw allow 'Nginx Full'
    sudo ufw enable
    
  11. 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
    
  12. 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
    
  13. Useful Commands

    Restart Gunicorn:

    sudo systemctl restart gunicorn
    

    View logs:

    journalctl -u gunicorn -f
    

    Restart Nginx:

    sudo systemctl restart nginx
    
  14. Directory Structure (Final)

    /home/ubuntu/apps/django_project/
    │── venv/
    │── projectname/
    │── manage.py
    │── gunicorn.sock
    │── staticfiles/
    
  15. Hardening for Production

    Recommended security additions:
    • Use .env file 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

Summary (TL;DR)

  1. Create venv → install Django + Gunicorn
  2. Configure PostgreSQL (optional)
  3. Run migrations + collectstatic
  4. Create Gunicorn systemd service
  5. Configure Nginx reverse proxy
  6. Enable HTTPS via Certbot
  7. Harden security + optimize

Your Django 6 app is now running in production.

Launch 100% ssd ubuntu vps from $3. 19/mo!

Conclusion

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

Avatar of editorial staff

Editorial Staff

Rad Web Hosting is a leading provider of web hosting, Cloud VPS, and Dedicated Servers in Dallas, TX.
lg