[Fixed]-Deploying django by python manage.py runserver to production on VPS

6👍

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!

3👍

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.

Leave a comment