How to Deploy Django with Nginx and uWSGI: A Step‑by‑Step Guide

This article walks through fixing missing static files, collecting assets, restarting uWSGI, and applying essential Django settings and template tweaks to successfully deploy a Django application in a production environment using Nginx and uWSGI.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Deploy Django with Nginx and uWSGI: A Step‑by‑Step Guide

Running a Django app locally is easy with the built‑in runserver, but production deployment requires handling static files, security, and efficiency.

Fixing missing static files

When Debug is off and Nginx is not yet configured, you can serve static assets directly by running:

python manage.py runserver 0.0.0.0:8000 --insecure

Collect static files

Before handing over to Nginx, gather all static resources into the static directory:

python manage.py collectstatic

Restarting uWSGI

Create a restart.sh script in the same directory as manage.py with the following commands to reload uWSGI after code changes:

killall uwsgi
uwsgi -x django_socket.xml

Replace django_socket.xml with the actual configuration file name.

Additional project tweaks

Add DOMAIN = '127.0.0.1' (or your actual IP/domain) to settings.py.

Update the base.html template to reference static assets, e.g., change the favicon link to /static/favicon.ico.

In the URL configurations of accounts and people apps, prefix view imports with apps. (e.g., apps.accounts.views).

Consider securing the admin interface by changing its URL or restricting IP ranges.

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.

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