Apache2 mod_wsgi,500内部服务器错误

时间:2011-04-19 08:36:40

标签: django apache2 mod-wsgi

我使用Apache2设置django App,

1)虚拟主机:

<VirtualHost *:80>
    ServerAdmin webadmin@publisy.com
    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脚本(位于/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()

有人可以说明出了什么问题吗?

3 个答案:

答案 0 :(得分:6)

似乎有一点问题。看起来您的“网站”目录是/var/www/mysite

将它添加到django.wsgi中的python路径。

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

事实上你发布的错误

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

似乎wsgi无法找到模块目的地。将目录路径添加到django.wsgi中的python路径,它应该可以工作。

答案 1 :(得分:1)

如果您有DEBUG=False或您的IP地址不在INTERNAL_IPS任何django错误,则会给出错误500,甚至是KeyError之类的内容。通常,生产服务器在调用中有差异,因此,即使在localhost上运行正常,您也可能在生产中发现一些问题。

有两种方法可以看出错误:

  1. 只需将您的IP添加到INTERNAL_IPS(获取您当前的IP地址)或将DEBUG设置为true
  2. 请查看apache error.log或您在settings.py中设置的电子邮件(默认情况下会通过电子邮件发送错误)
  3. 另外,请记住,您必须在进行更改后重新启动服务器。

    祝你好运!

答案 2 :(得分:1)

Traceback Switch to copy-and-paste view

/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in get_response
                response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py in wrapper
            return self.admin_view(view, cacheable)(*args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py in _wrapped_view
                response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py in               _                       s    wrapped_view_func
    response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py in inner
        return view(request, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py in _         s        s     wrapped_view_func
    response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py in index
                        model_dict['admin_url'] = reverse('admin:%s_%s_changelist' % info,     current_app=self.name) ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in reverse
            app_list = resolver.app_dict[ns] ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in app_dict
        self._populate() ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in _populate
    for pattern in reversed(self.url_patterns): ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in url_patterns
        raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it"         %      self.urlconf_name) ...
    ▶ Local vars