Search code examples
djangoapache2mod-wsgi

Apache2 mod_wsgi, 500 Internal Server Error


I setup, django App with Apache2,

1) Virtual host:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName alpha101.publisy.com
    DocumentRoot /var/www/mysite

    WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi
    Alias /static/ /var/www/mysite/media/static/
    <Directory /var/www/mysite/media/static>
        Order deny,allow
        Allow from all
    </Directory>

    Alias /media/ /var/www/mysite/media/
    <Directory /var/www/mysite/media>
        Order deny,allow
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

</VirtualHost>

2) wsgi script (located at /usr/local/django/mysite/apache/django.wsgi)

import os, sys
sys.path.append('/usr/local/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Can anybody suggest what goes wrong?


Solution

  • There seems to be a little problem. Looks like your "site' directory is /var/www/mysite.

    Add this to your python path in django.wsgi.

    sys.path.append('/var/www')
    sys.path.append('/var/www/mysite')
    

    Infact the error you posted

    TemplateSyntaxError: Caught an exception while rendering: No module named destinations 
    

    It seems that wsgi can't find the module destinations. Add the directory path to your python path in django.wsgi and it should work.