简体   繁体   中英

mod_wsgi with Django 500 error

I'm using Ubuntu 14.04, Apache 2.4, Python 2.7.6, Django 1.9.5 and mod_wsgi 4.5.1 installed from source.

My folder structure looks like so:

project
 -site
   -mysite
      -apache
         -wsgi.py

wsgi.py:

import os, sys

from django.core.wsgi import get_wsgi_application
sys.path.append('/home/me/project/site')
sys.path.append('/home/me/project/site/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'


application = get_wsgi_application()

In my main /etc/apache2/sites-enabled/000-default.conf file I have only edited the following

<VirtualHost *:80>

ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

    WSGIScriptAlias / /home/seb/project/funel/mysite/apache/wsgi.py
            <Directory "/home/seb/project/funel/mysite/apache">
                    Require all granted
            </Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

What am I doing wrong? I seem to be getting a 500 Internal Server Error even though restarting Apache doesn't show any problems.

It sound like your apache configuration is giving you most of the problems. Please try to write to a log file from within wsgi.py file and determine if the server atleast uses the correct wsgi file.

For what it is worth I am attaching contents of a_django_site.conf apache config file. this file should be in /etc/apache2/sites-available and should be enabled using sudo a2ensite a_django_site.conf thereafter reload and restart.

Define MY_IP=129.222.333.444
WSGIPythonPath  /home/your_name/.virtualenvs/venv_proj_name/bin/python:/home/your_name/.virtualenvs/venv_proj_name/lib/python2.7/site-packages


<VirtualHost *:80>
ServerAdmin root@localhost
ServerName {MY_IP}
ServerAlias http://{MY_IP}/

DocumentRoot /usr/local/src/proj_dir

Alias /static /usr/local/src/proj_dir/django_static/
Alias /images /usr/local/src/proj_dir/stock/media/
Alias /favicon.ico /usr/local/src/proj_dir/apache/favicon.png

WSGIScriptAlias / /usr/local/src/proj_dir/proj_name/wsgi.py

<Directory />
    Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM