开发者

Apache2 mod_wsgi, 500 Internal Server Error

开发者 https://www.devze.com 2023-02-27 03:38 出处:网络
I setup, django App with Apache2, 1) Virtual host: <VirtualHost *:80> ServerAdmin webadmin@publisy.com

I setup, django App with Apache2,

1) Virtual host:

<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/apa开发者_StackOverflowche2/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?


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.


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!


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
0

精彩评论

暂无评论...
验证码 换一张
取 消