1

这是我关于 SO 的第一篇文章。我太沮丧了,无法继续研究这个问题,所以我只想发布我的设置,看看是否有人愿意提供帮助。

当我将 Apache 作为服务(作为管理员)运行时,首先,文档根目录允许我通过 url 访问我的文件(不是很酷,但不是我的问题,因为我知道这是 Apache conf 中的文档根目录设置)。其次,当我输入 127.0.0.1/blog/blog/ 时,它会引发 500 错误,并且 Apache 日志显示:

[Tue Sep 24 19:44:20 2013] [info] mod_wsgi (pid=2152): Create interpreter '127.0.0.1|/blog'.
[Tue Sep 24 19:44:20 2013] [info] mod_wsgi (pid=2152): Adding 'C:/Users/jdp/Documents/www/mysite.com' to path.
[Tue Sep 24 19:44:20 2013] [info] [client 127.0.0.1] mod_wsgi (pid=2152, process='', application='127.0.0.1|/blog'): Loading WSGI script 'C:/Users/jdp/Documents/www/mysite.com/mysite/wsgi.py'.
[Tue Sep 24 19:49:40 2013] [info] [client 127.0.0.1] (OS 10053)An established connection was aborted by the software in your host machine.  : core_output_filter: writing data to the network
[Tue Sep 24 19:49:40 2013] [error] [client 127.0.0.1] mod_wsgi (pid=2152): Exception occurred processing WSGI script 'C:/Users/jdp/Documents/www/mysite.com/mysite/wsgi.py'.
[Tue Sep 24 19:49:40 2013] [error] [client 127.0.0.1] IOError: failed to write data
[Tue Sep 24 19:49:48 2013] [info] [client 127.0.0.1] (OS 10053)An established connection was aborted by the software in your host machine.  : core_output_filter: writing data to the network
[Tue Sep 24 19:49:48 2013] [error] [client 127.0.0.1] mod_wsgi (pid=2152): Exception occurred processing WSGI script 'C:/Users/jdp/Documents/www/mysite.com/mysite/wsgi.py'.
[Tue Sep 24 19:49:48 2013] [error] [client 127.0.0.1] IOError: failed to write data
[Tue Sep 24 19:52:10 2013] [info] [client 127.0.0.1] (OS 10053)An established connection was aborted by the software in your host machine.  : core_output_filter: writing data to the network
[Tue Sep 24 19:52:10 2013] [error] [client 127.0.0.1] mod_wsgi (pid=2152): Exception occurred processing WSGI script 'C:/Users/jdp/Documents/www/mysite.com/mysite/wsgi.py'.
[Tue Sep 24 19:52:10 2013] [error] [client 127.0.0.1] IOError: failed to write data

顺便说一句,在窗户上。

首先:http.conf:

WSGIPythonPath C:/Users/jdp/Documents/www/mysite.com

<VirtualHost *:80>
    ServerName 127.0.0.1
    ServerAlias randomserver.com
    ServerAdmin randomguy@example.com

    DocumentRoot C:/Users/usr/Documents/www/

    <Directory C:/Users/usr/Documents/www/>
    Order allow,deny
    Allow from all
    </Directory>

    WSGIPassAuthorization On

    WSGIScriptAlias /blog C:/Users/usr/Documents/www/mysite.com/mysite/wsgi.py


    <Directory C:/Users/usr/Documents/www/mysite.com/mysite>
    <Files wsgi.py>
    Order deny, allow
    Allow from all
    </Files>
    </Directory>
</VirtualHost>

最初我试图这样做:

WSGIPythonPath C:/Users/usr/Documents/www/mysite.com:C:/Users/jdp/Documents/site/env/Lib/site-packages

但这导致路径 #1 出现问题,我无法导入 mysite.settings。我忽略了它,只是将丢失的包下载到我的根 python 目录。

这是我在 C:/Users/usr/Documents/www/mysite.com/mysite/settings.py 中的设置

DEBUG = False
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'django_db',                      
        'USER': 'usr',
        'PASSWORD': '*******',
        'HOST': '127.0.0.1',                      
        'PORT': '0080',                      
    }
}

ALLOWED_HOSTS = ['*']


TIME_ZONE = 'America\New_York'


LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True

USE_L10N = True


USE_TZ = True


MEDIA_ROOT = r'C:\Users\usr\Documents\site\mysite\media'

MEDIA_URL = 'media/'

STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = (

)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

SECRET_KEY = '*********************************'

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

WSGI_APPLICATION = 'mysite.wsgi.application'

TEMPLATE_DIRS = (
    'C:/Users/usr/Documents/www/mysite.com/templates',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'blog',
    'south',
    'django.contrib.markup',
)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }

}

啊啊啊这是我的 wsgi.py 文件:

import os

os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

和我的 urls.py:

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

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

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

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    url(r'^blog/', include('blog.urls', namespace='blogs')),
)

不确定是否有任何其他信息有用。任何帮助将不胜感激!我花了太多时间尝试进行小调整并搜索 SO 和 mod_wsgi 文档,但收效甚微。由于我是编程新手,也许我咬得比我能咀嚼的更多,但我认为我还没有被这样困住。

4

2 回答 2

1

您不应将项目源代码放在 DocumentRoot 下,该文件记录在:

这将确保您的源代码不可访问。

500 错误是因为您的代码损坏,并且您可能没有正确设置 Django 以其他方式记录错误的详细信息。您似乎正在尝试使用日志系统将错误通过电子邮件发送给您,但这些消息可能无法通过,因为您尚未设置 ADMINS。

启用调试模式允许错误显示在浏览器中。

FWIW,错误:

IOError: failed to write data

是因为您的浏览器的连接在任何响应被写回之前就被终止了。您可能已经强制重新加载页面或其他内容。

于 2013-09-25T01:14:44.133 回答
0

@Foon @格雷厄姆邓普顿

谢谢!一旦我更改了我的数据库设置以匹配我在 PGAdmin 中的 postgres 设置并修复了时区错误,我的页面就会加载。

DEBUG = False
TEMPLATE_DEBUG = DEBUG

ADMINS = (
     ('usr', 'usr@gmail.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', 
        'NAME': 'django_db',    
        'USER': 'usr',
        'PASSWORD': 'blahblahblah',
        'HOST': 'localhost',                    
        'PORT': '5432',                     
    }
}

ALLOWED_HOSTS = ['*']

TIME_ZONE = 'America/New_York'

现在我只需要弄清楚如何在服务器上配置我的静态文件。

于 2013-09-25T11:53:22.053 回答