What is Django & Why Deploy on Cloud?
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It powers some of the world's largest websites — Instagram, Pinterest, and Disqus among them. Deploying Django on cloud hosting gives you on-demand scalability, better uptime, and full control over your server environment.
HostGraber's Cloud Hosting is optimized for Python and Django applications — with NVMe SSD storage, root SSH access, and one-click server provisioning. This guide walks you through the entire deployment process step by step.
Prerequisites
✅Ubuntu 22.04 LTS server
✅Python 3.10+ installed
✅A Django project ready to deploy
✅Basic SSH / Linux knowledge
1
Connect to Your Cloud Server via SSH
After provisioning your HostGraber Cloud server, connect to it using SSH from your local terminal. Replace your_server_ip with the IP address from your HostGraber dashboard.
💡
Tip: Use SSH key authentication instead of a password for better security. You can add your public key from the
HostGraber control panel.
2
Update the Server & Install Dependencies
Always start by updating your server packages and installing Python, pip, and other required tools.
apt update && apt upgrade -y
apt install -y python3 python3-pip python3-venv
apt install -y nginx git curl ufw
3
Clone Your Django Project
Clone your project from GitHub or upload it via SCP/SFTP. We recommend keeping your project in /var/www/.
cd /var/www/
git clone https://github.com/yourusername/your-django-project.git
cd your-django-project
4
Create a Virtual Environment & Install Requirements
Always use a Python virtual environment to isolate your project dependencies from the system Python.
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install gunicorn
💡 Note: Make sure your requirements.txt includes django, gunicorn, and any database adapters like psycopg2-binary.
5
Configure Django Settings for Production
Open your settings.py and make these critical production changes:
# settings.py
DEBUG = False
ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com', 'your_server_ip']
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
⚠️ Important: Never run Django in production with DEBUG = True. It exposes sensitive information including your secret key and database settings.
Then collect all static files:
python manage.py collectstatic
python manage.py migrate
6
Set Up Gunicorn as the WSGI Server
Gunicorn serves as the Python WSGI HTTP server between your Django app and Nginx. Test it first:
gunicorn --bind 0.0.0.0:8000 your_project_name.wsgi
Now create a systemd service file to keep Gunicorn running persistently:
nano /etc/systemd/system/gunicorn.service
Paste the following configuration:
[Unit]
Description=Gunicorn daemon for Django
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/var/www/your-django-project
ExecStart=/var/www/your-django-project/venv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
your_project_name.wsgi:application
[Install]
WantedBy=multi-user.target
Enable and start Gunicorn:
systemctl daemon-reload
systemctl start gunicorn
systemctl enable gunicorn
systemctl status gunicorn
7
Configure Nginx as a Reverse Proxy
Nginx handles incoming HTTP requests and forwards them to Gunicorn. Create a new server block:
nano /etc/nginx/sites-available/your-django-project
Add the following configuration:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /var/www/your-django-project;
}
location /media/ {
root /var/www/your-django-project;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
Enable the config and restart Nginx:
ln -s /etc/nginx/sites-available/your-django-project /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
8
Secure with SSL (Free Let's Encrypt)
Secure your Django app with a free SSL certificate using Certbot. HostGraber also offers managed SSL certificates for one-click setup.
apt install -y certbot python3-certbot-nginx
certbot --nginx -d yourdomain.com -d www.yourdomain.com
Certbot will automatically configure Nginx for HTTPS and set up auto-renewal. Verify renewal works:
9
Configure Firewall (UFW)
Allow only essential ports for security:
ufw allow OpenSSH
ufw allow 'Nginx Full'
ufw enable
ufw status
10
Test Your Live Django Application
Visit your domain in a browser. If everything is configured correctly, your Django app will be live over HTTPS. To debug any issues, check the logs:
# Gunicorn logs
journalctl -u gunicorn --no-pager
# Nginx error log
tail -f /var/log/nginx/error.log
# Nginx access log
tail -f /var/log/nginx/access.log
Quick Reference: Django Deployment Stack
| Component |
Role |
Why It's Used |
| Django |
Python Web Framework |
Handles app logic, routing, ORM & admin |
| Gunicorn |
WSGI Application Server |
Serves Django to Nginx via Unix socket |
| Nginx |
Reverse Proxy / Web Server |
Handles HTTP/S, static files & load balancing |
| Virtualenv |
Python Environment |
Isolates project dependencies |
| Certbot / SSL |
SSL Certificate Manager |
Enables HTTPS with auto-renewal |
| UFW Firewall |
Network Security |
Restricts ports, blocks unauthorized access |
Ready to Deploy Django?
Host Your Django App on HostGraber
Get NVMe SSD cloud servers, root SSH access, free SSL, and 99.99% uptime — purpose-built for Python & Django deployments. Plans start at just ₹49/month.
Conclusion
Deploying Django on cloud hosting is the right move for any production-grade Python web application. With Gunicorn as your WSGI server, Nginx as a reverse proxy, SSL via Certbot, and a locked-down firewall — your app is secure, fast, and scalable.
HostGraber Cloud Hosting gives you a managed, high-performance environment to run Django apps with confidence. Need help? Our 24/7 support team is always available to assist with your deployment.