Operations 6 min read

How to Deploy a Django App with uWSGI, Nginx, and HTTPS – Step‑by‑Step Guide

This guide walks you through creating a Django project, configuring uWSGI and an INI file, setting up Nginx as a reverse proxy, enabling HTTPS with SSL certificates, collecting static files, and scaling the deployment for high availability, all with clear command‑line examples.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Deploy a Django App with uWSGI, Nginx, and HTTPS – Step‑by‑Step Guide

Create a Django project

Start a new Django project named django_deployment and allow external hosts. django-admin startproject django_deployment In settings.py set:

ALLOWED_HOSTS = ["*"]

Run a simple uWSGI application with a Python file

def application(env, start_response):
    start_response('200 OK', [('Content-type', 'text/html')])
    return [b'Hello uWSGI.']

Start it with:

uwsgi --http-socket :8000 --plugin python3 --wsgi-file uwsgi_test.py

If uWSGI is not installed, install the required plugins:

sudo apt install uwsgi-plugin-common
sudo apt install uwsgi-plugin-python3

Configure uWSGI for the Django project

Create django-uwsgi.ini with the following content:

[uwsgi]
chdir = /source/python/deployment/django_deployment
module = django_deployment.wsgi
http-socket = :8000
master = True
processes = 4
threads = 1
vacuum = true

Start uWSGI using the ini file:

uwsgi --ini django-uwsgi.ini

Set up Nginx as a reverse proxy

Backup the existing nginx.conf and edit it to add an upstream and server block:

upstream uwsgi {
    server 122.51.1.19:8000;
}
server {
    listen 80;
    server_name 122.51.1.19;
    charset utf-8;
    location / {
        proxy_pass http://uwsgi;
    }
}

Reload Nginx:

nginx -s reload

Collect static files

In settings.py add: STATIC_ROOT = os.path.join(BASE_DIR, 'static') Then run: python manage.py collectstatic Update the Nginx server block to serve the static directory:

location /static {
    alias /source/python/deployment/django_deployment/static;
}

Enable HTTPS

Obtain an SSL certificate and copy .crt and .key files to /etc/nginx/ssl. Add an HTTPS server block:

listen 443 ssl;
ssl_certificate /etc/nginx/ssl/domain.com.crt;
ssl_certificate_key /etc/nginx/ssl/domain.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

Redirect HTTP to HTTPS:

server {
    listen 80;
    server_name topic.akashi.org.cn;
    return 301 https://$host$request_uri;
}

Reload Nginx again:

nginx -s reload

High‑availability configuration

Define multiple uWSGI back‑ends with weights for load balancing:

upstream uwsgi {
    server 127.0.0.1:8000 weight=3;
    server 127.0.0.1:8001 weight=1;
}

Do not run uWSGI as root and disable external access to the uWSGI socket.

Monitoring and management

Check running processes:

ps -aux | grep uwsgi
ps -aux | grep nginx

View logs: tail -f /var/log/nginx/nginx.log Stop uWSGI gracefully using the PID file: uwsgi --stop /path/to/uwsgi-8000.pid All commands are shown without additional styling to keep the HTML clean and focused on the core deployment steps.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonDeploymentDjangoHTTPSuwsgi
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.