简体   繁体   English

新手对mod_wsgi / apache / django设置感到困惑

[英]Newbie confounded by mod_wsgi/apache/django settings

this is my first post on SO. 这是我关于SO的第一篇文章。 I've become too frustrated to continue researching this, so I'm just going to post my settings and see if someone is willing to help. 我太沮丧了,无法继续研究它,所以我将发布设置,看看是否有人愿意提供帮助。

When I run Apache as a service (as an administrator), first off, the document root allows me to access my files through url (not cool, but not really my issue because I know it's the document root setting in the Apache conf). 首先,当我运行Apache作为服务(以管理员身份)时,文档根目录允许我通过url访问文件(虽然不酷,但实际上不是我的问题,因为我知道这是Apache conf中的文档根目录设置)。 Secondly, when I type in 127.0.0.1/blog/blog/ it throws a 500 error and the Apache log reads: 其次,当我键入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

On windows, by the way. 顺便说一句,在Windows上。

first up: http.conf: 首先: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>

originally I was attempting to do: 最初我试图做的是:

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

but that caused problems with the path #1 and I couldn't import mysite.settings. 但这导致路径#1出现问题,我无法导入mysite.settings。 I left it out and just downloaded the missing packages to my root python directory. 我忽略了它,只是将缺少的软件包下载到了我的python根目录。

Here are my settings in C:/Users/usr/Documents/www/mysite.com/mysite/settings.py 这是我在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,
        },
    }

} }

Aaaaaaand here's my wsgi.py file: 这是我的wsgi.py文件:

import os

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

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

and my urls.py: 和我的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')),
)

Not sure if any other information would be useful. 不知道其他信息是否有用。 Any help would be greatly appreciated! 任何帮助将不胜感激! I've spent too many hours trying little tweaks and searching SO and the mod_wsgi documentation to little avail. 我花了太多时间尝试进行一些细微的调整,并搜索SO和mod_wsgi文档而徒劳无功。 Maybe I'm biting off more than I can chew since I'm new to programming, but I don't think I've been stuck like this yet. 由于我是编程新手,所以我可能会付出太多努力,但我不认为自己已经被这样的困扰了。

You should not put your project source code under DocumentRoot, that is documented in: 您不应将项目源代码放在DocumentRoot下,该文档记录在:

That will ensure your source code is not accessible. 这将确保您的源代码不可访问。

The 500 error was because of your broken code and because you perhaps hadn't otherwise correctly setup Django to log details of the error in some other way. 500错误是由于您的代码损坏而引起的,也可能是因为您可能没有正确设置Django以其他方式记录错误的详细信息。 You appear to be trying to have it email you the errors using the logging system, but those messages may not be getting through because you haven't set ADMINS. 您似乎正在尝试使用日志记录系统将其通过电子邮件发送给您错误消息,但是由于您尚未设置ADMINS,因此这些消息可能无法通过。

Enabling DEBUG mode allowed the error to be shown in the browser instead. 启用调试模式可以使错误显示在浏览器中。

FWIW, the error: FWIW,错误:

IOError: failed to write data

is because the connection from your browser was killed before any response could be written back. 这是因为在可以写回任何响应之前,已终止了来自浏览器的连接。 You may have forced a page reload or something. 您可能已强制重新加载页面或其他内容。

@Foon @Graham Dumpleton @Foon @Graham Dumpleton

Thanks! 谢谢! Once I changed my database settings to match my postgres settings in PGAdmin and fixed the timezone bug, my page loads. 一旦我更改了数据库设置以使其与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'

Now I just need to figure out how to configure my static files on a server. 现在,我只需要弄清楚如何在服务器上配置我的静态文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM