2013-09-24 21 views
1

这是我在SO上的第一篇文章。我对于继续研究这个问题感到非常沮丧,所以我只会发布我的设置,看看有人愿意提供帮助。新手受到mod_wsgi/apache/django设置的困扰

当我作为服务运行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 

在Windows上,顺便说一句。

先达:在http.conf:

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

<VirtualHost *:80> 
    ServerName 127.0.0.1 
    ServerAlias randomserver.com 
    ServerAdmin [email protected] 

    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', '[email protected]'), 
) 

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这里是我的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')), 
) 

不确定是否有其他信息会有用。任何帮助将不胜感激!我花了太多时间来尝试一些小小的调整,并且在搜索和mod_wsgi文档时没有多大用处。也许我因为我刚刚接触编程而感到咬牙切齿,但我认为我还没有被这样卡住。

+0

只是为了检查,你能成功地执行python manage.py runserver吗? (然后连接到localhost:8000) – Foon

+0

另外,我不认为这是你的问题,但你的settings.py中的postgres端口可能不应该是0080;一般是4321 IIRC。 – Foon

+0

与此相关http://support.microsoft.com/kb/204594?也许在8080这样的高编号端口上尝试Apache。 – AndrewS

回答

1

你不应该把你的项目源代码的DocumentRoot下,在被记载:

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

500错误是因为您的代码损坏,因为您可能没有正确设置Django以其他方式记录错误的详细信息。您好像试图让它使用日志记录系统向您发送错误消息,但这些消息可能没有通过,因为您尚未设置ADMINS。

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

FWIW,错误:

IOError: failed to write data 

是因为从你的浏览器的连接被杀死任何响应可以写回来。你可能已经强迫一个页面重新加载或什么的。

+0

看起来我在设置虚拟主机时误解了您的文档,这就是为什么我将文档根目录设置为该目录。我想保留在文档根目录下的是什么?只要WSGIAlias设置正确,网站是否会加载? –

+0

但您的网站位于子网址,因此该子网址之外的任何内容仍会映射到DocumentRoot以获取静态文件等。 –

0

@Foon @Graham Dumpleton

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

DEBUG = False 
TEMPLATE_DEBUG = DEBUG 

ADMINS = (
    ('usr', '[email protected]'), 
) 

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' 

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