This is a compact checklist for deploying a Django project on an Ubuntu VPS with Gunicorn and Nginx.
Prepare the server
Create a dedicated user and install the system packages:
sudo adduser django
sudo usermod -aG sudo django
sudo apt update
sudo apt install python3-venv python3-pip nginx git
Clone the project and create the virtual environment:
git clone git@example.com:project.git
cd project
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
Configure Django
Use production settings, set DEBUG = False, configure ALLOWED_HOSTS, and
provide the required secrets through environment variables or a local settings
file.
Run migrations and collect static files:
python manage.py migrate
python manage.py collectstatic --no-input
Run Gunicorn with systemd
Create a systemd service similar to this:
[Unit]
Description=Django application
After=network.target
[Service]
User=django
Group=www-data
WorkingDirectory=/home/django/project
ExecStart=/home/django/project/env/bin/gunicorn project.wsgi:application
[Install]
WantedBy=multi-user.target
Enable it:
sudo systemctl daemon-reload
sudo systemctl enable --now django.service
Put Nginx in front
Configure Nginx as a reverse proxy:
server {
server_name example.com;
location /static/ {
alias /home/django/project/staticfiles/;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Reload Nginx:
sudo nginx -t
sudo systemctl reload nginx