本文介绍了使用Django 1.6在EC2上,django.wsgi 500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成安装(或试图安装)的EC2服务器上的Django 1.6,但我似乎有与django.wsgi麻烦。

I've just finished installing (or attempting to install) Django 1.6 on an EC2 server, but I seem to be having trouble with django.wsgi.

我已经安装的Django 1.6,httpd的,和mod_wsgi的,而我得到的服务器遇到一个内部错误或配置错误,无法完成您的请求。

I've installed Django 1.6, httpd, and mod_wsgi, and I'm getting the "The server encountered an internal error or misconfiguration and was unable to complete your request.

请与服务器管理员联系,根@本地...

Please contact the server administrator, root@localhost..."

我得到我的地方做了一个失误,但我似乎无法分辨出错误日志正在试图告诉我什么。我看到有底部附近一些数据库错误,我还没有得到来设置任何上去过,但肯定是错误以上是来自一个不同的问题?

I get that I've made a misstep somewhere, but I can't seem to make out what the error logs are trying to tell me. I see there are some database errors near the bottom, and I haven't gotten to setting any up yet, but surely the errors above are from a different issue?

下面是从错误日志中最新的:

Here's is the latest from the error log:

[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] mod_wsgi (pid=1973): Exception occurred processing WSGI script '/home/ec2-user/Django-1.6/joshsite/apache/django.wsgi'.
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] Traceback (most recent call last):
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     self.load_middleware()
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     mw_class = import_by_path(middleware_path)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/utils/module_loading.py", line 21, in import_by_path
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     module = import_module(module_path)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     __import__(name)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/middleware.py", line 3, in <module>
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     from django.contrib.auth.backends import RemoteUserBackend
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/backends.py", line 3, in <module>
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     from django.contrib.auth.models import Permission
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 48, in <module>
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     class Permission(models.Model):
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 96, in __new__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     new_class.add_to_class('_meta', Options(meta, **kwargs))
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 264, in add_to_class
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     value.contribute_to_class(cls, name)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/options.py", line 124, in contribute_to_class
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 34, in __getattr__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     return getattr(connections[DEFAULT_DB_ALIAS], item)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 198, in __getitem__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     backend = load_backend(db['ENGINE'])
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 131, in load_backend
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     raise ImproperlyConfigured(error_msg)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] ImproperlyConfigured: 'mysql' isn't an available database backend.
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] Try using 'django.db.backends.XXX', where XXX is one of:
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] Error was: No module named mysql.base
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] mod_wsgi (pid=1976): Exception occurred processing WSGI script '/home/ec2-user/Django-1.6/joshsite/apache/django.wsgi'.
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] Traceback (most recent call last):
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     self.load_middleware()
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     mw_class = import_by_path(middleware_path)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/utils/module_loading.py", line 21, in import_by_path
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     module = import_module(module_path)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     __import__(name)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/middleware.py", line 3, in <module>
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     from django.contrib.auth.backends import RemoteUserBackend
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/backends.py", line 3, in <module>
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     from django.contrib.auth.models import Permission
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 48, in <module>
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     class Permission(models.Model):
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 96, in __new__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     new_class.add_to_class('_meta', Options(meta, **kwargs))
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 264, in add_to_class
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     value.contribute_to_class(cls, name)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/options.py", line 124, in contribute_to_class
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 34, in __getattr__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     return getattr(connections[DEFAULT_DB_ALIAS], item)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 198, in __getitem__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     backend = load_backend(db['ENGINE'])
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 131, in load_backend
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     raise ImproperlyConfigured(error_msg)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] ImproperlyConfigured: 'mysql' isn't an available database backend.
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] Try using 'django.db.backends.XXX', where XXX is one of:
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] Error was: No module named mysql.base

我的django.wsgi如下:

My django.wsgi is as follows:

import os,sys

apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append('/home/ec2-user/Django-1.6/joshsite/joshsite')
sys.path.append('/home/ec2-user/Django-1.6/joshsite')

os.environ['DJANGO_SETTINGS_MODULE'] = 'joshsite.settings'

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

和我添加这到httpd.conf

And I've added this in to the httpd.conf

<VirtualHost *:80>
    DocumentRoot /home/ec2-user/Django-1.6/joshsite
    ServerName ec2-54-187-46-240.us-west-2.compute.amazonaws.com
    ErrorLog /home/ec2-user/Django-1.6/joshsite/logs/apache_error.log
    CustomLog /home/ec2-user/Django-1.6/joshsite/logs/apache_access.log combined
    WSGIScriptAlias / /home/ec2-user/Django-1.6/apache/django.wsgi


    <Directory /home/ec2-user/Django-1.6/joshsite/media>
        Order deny,allow
        Allow from all
    </Directory>

    <Directory /home/ec2-user/Django-1.6/apache>
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn

    Alias /media/ /ec2-user/Django-1.6/joshsite/media/
</VirtualHost>

下面是settings.py的内容:

Here are the contents of settings.py:

"""
Django settings for joshsite project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ***

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'joshsite.urls'

WSGI_APPLICATION = 'joshsite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
       'ENGINE': 'django.db.backends.mysql',
        'NAME': 'test',
        'USER': '**',
        'PASSWORD': '**',
        'HOST': '',
        'PORT': '',
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

下面是我的urls.py:

Here is my urls.py:

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'joshsite.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^home/', 'joshsite.views.home', name='home'),
)

更新:有时在/,我得到一个404错误:

Update:Sometimes at /, I get a 404 error:

Request Method: GET
Request URL:    http://ec2-54-187-46-240.us-west-2.compute.amazonaws.com/
Using the URLconf defined in joshsite.urls, Django tried these URL patterns, in this order:
^admin/
^home/ [name='home']
The current URL, , didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Thank you in advance for any assistance.

但随后刷新后有时可以追溯到500,仿佛随意选择。

But then after refreshing it sometimes goes back to a 500, almost as if chosen at random.

推荐答案

检查数据库 settings.py 。看起来像你的发动机是坏的。请尝试更改为:

Check your DATABASE settings in settings.py. Looks like your ENGINE is bad. Try changing to:

'ENGINE': 'django.db.backends.mysql',

如果这还不奏效,请发表您的数据库设置。

If this doesn't work, please post your database settings.

这篇关于使用Django 1.6在EC2上,django.wsgi 500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 01:57