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.
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 --insecureCollect static files
Before handing over to Nginx, gather all static resources into the static directory:
python manage.py collectstaticRestarting 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.xmlReplace 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
