I've bought a VPS for my django app. I've never ever before deployed django, or any other application. I've read a few tutorials on how to deploy django using apache and wsgi and some other options gunicorn, ngix. To me it all seems very frustrating and hard to understand. I was wondering what would happen if I deployed my application by changing debug to false, creating a database, plugging it in and then simply running python manage.py runserver my-ip. Is this a bad practice ?
-
13There's a lot of hate here, but I think it's a valuable question - the documentation I've read doesn't explain why you need a web server, gunicorn etc, and since I can serve my dev server without one it's interesting to know what they are providing that is so necessary. – owencm Jun 14 '15 at 05:38
-
1I also don't understand why no one can provide an adequate answer beyond "just don't". Has accepting dictums without understanding the underlying rationale ever been a good idea? – Alex Petralia Mar 28 '17 at 18:56
-
The main reason is that the Django server is not considered secure. Generally-speaking data needs protection even within a protected environment, which makes the manage.py runserver unsuitable for production. – aris Jan 19 '19 at 17:44
2 Answers
It is easy to learn how to deploy a Django project.
At first, you should know how to install Apache
and mod_wsgi
if you use Ubuntu
sudo apt-get install apache2 libapache2-mod-wsgi
or Fedora
(red hat) (without test)
yum install httpd mod_wsgi
Then, you should know how to associate Apache2 with your Django project
<VirtualHost *:80>
ServerName example.com
ServerAdmin example@example.com
Alias /media/ /home/tu/blog/media/
<Directory /home/tu/blog/media>
Require all granted
</Directory>
WSGIScriptAlias / /home/tu/blog/blog/wsgi.py
<Directory /path/to/django/project/wsgifile>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
The sentence WSGIScriptAlias
associate Apache2 configuration with your Django project
in Django wsgi.py
file, you will see project.settings
included, that is how it works
The following may be easy to understand how it works
*.conf --> wsgi.py --> settings.py --> urls.py and apps
just search in Google like ubuntu django server mod_wsgi
and learn it yourself!

- 6,010
- 8
- 36
- 52

- 6,124
- 4
- 37
- 51
Do not do use the dev server in production. Just don't.
At the very least serve it off gunicorn:
$ pip install gunicorn
$ cd your_project
$ gunicorn project.wsgi # gunicorn now runs locally on port 8000
And have nginx (or apache) as a reverse proxy:
server {
location / {
proxy_pass http://127.0.0.1:8000;
}
}
Deploying Django (just like any other application) is a world in and of itself, and mastering it takes time. But don't ever run the development server in production.

- 161,610
- 92
- 305
- 395
-
5Could you please explain why I need gunicorn and nginx or apache? I take your word on it that I do, but I'd like to understand what they're providing me. – owencm Jun 14 '15 at 05:39
-
3Why not use development server in production in very small scale scenarios? Add explanation please. See http://serverfault.com/q/717568/134848. – a06e Aug 28 '15 at 19:06
-
-
1@Ricky - from the Django docs: "DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests." – Yuval Adam Aug 12 '21 at 07:21
-
Well, you would only need nginx as a reverse proxy if you serve static files, in case your django app is an API, you only would need gunicorn. – redigaffi Oct 13 '21 at 19:32