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 ?
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 [email protected]
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!
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.
© 2022 - 2024 — McMap. All rights reserved.