[Django]-Troubles with running django app via wsgi on ubuntu 17

3👍

Don’t set DocumentRoot to be a parent directory of your source code. If you were to take the WSGIScriptAlias out, people could download your source code. You should avoid the risk of that, even if WSGIScriptAlias currently intercepts everything under /. That DocumentRoot directory doesn’t allow access may be part of the problem also.

Try:

<VirtualHost *:80>

CustomLog /var/log/apache2/cardsite-access.log common
ErrorLog /var/log/apache2/cardsite-error.log

DocumentRoot /var/cardsite/htdocs

<Directory /var/cardsite/htdocs>
    Require all granted
</Directory>

Alias /static /var/cardsite/cardsite/static

<Directory /var/cardsite/cardsite/static>
    Require all granted
</Directory>

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

WSGIDaemonProcess cardsite python-path=/var/cardsite python-home=/var/venv_python36

WSGIProcessGroup cardsite
WSGIApplicationGroup %{GLOBAL}

WSGIScriptAlias / /var/cardsite/cardsite/wsgi.py

<Directory /var/cardsite/cardsite>
    <Files wsgi.py>
    Require all granted
    </Files>
</Directory>

</VirtualHost>

The WSGIApplicationGroup has been added as always a good idea to have that, with only one WSGI application delegated to the daemon process group.

Make sure you create the directory:

/var/cardsite/htdocs

Finally, you are missing a ServerName directive. So if this isn’t the default VirtualHost, your request may not even be getting handled by this VirtualHost.

Leave a comment