Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 468
Elisa Avatar asked Apr 19 '11 08:04

Elisa


2 Answers

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.

like image 52
Neo Avatar answered Sep 21 '22 00:09

Neo


If you have DEBUG=False or your ip address is not in the INTERNAL_IPS any django error will give you Error 500, even a thing like KeyError. Usually, production server has a diffences in the inviroment, so, even if everything ran ok on localhost, you might find some problems in production.

Two ways to see what is wrong:

  1. Just add your ip to INTERNAL_IPS (get your current ip address) or set DEBUG to true
  2. Take look at apache error.log or at the email that you have setup in your settings.py (errors are emailed by default)

Also, remember, that you have to restart the server after making changes.

Good luck!

like image 26
Silver Light Avatar answered Sep 22 '22 00:09

Silver Light