๐Ÿš€ 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!

๐Ÿš€ 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

  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:

    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