无法解决Django安装程序中的mod_wsgi异常 [英] Cannot solve mod_wsgi exception in Django setup

查看:359
本文介绍了无法解决Django安装程序中的mod_wsgi异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与托管服务提供商合作,以启动并运行Django应用程序,但是我们俩都不是非常有经验的人,我们基本上已经陷入了一个死胡同.

I'm working with my hosting provider to get a Django application up and running, but neither of us are very experienced and we've basically hit a complete dead end.

我没有直接访问conf文件的权限,但这是向我描述其内容的方式:

I don't have direct access to the conf file but here's how its contents have been described to me:

<IfModule mod_wsgi.c>
WSGIScriptAlias /fredapp/ /home/fred/public_html/cgi-bin/fredapp/apache/django.wsgi
WSGIDaemonProcess fred threads=15 display-name=%{GROUP} python-path=/home/fred/public_html/cgi-bin/fredapp/apache/
WSGIProcessGroup fred
WSGIApplicationGroup %{GLOBAL}
</IfModule>

Alias /robots.txt /home/fred/public_html/fred-site/robots.txt
Alias /favicon.ico /home/fred/public_html/fred-site/favicon.ico

Alias /settings/media/ /home/fred/public_html/fred-site/media/

我的"django.wsgi"脚本没什么花哨的:

My "django.wsgi" script is nothing fancy:

import os, sys
sys.path.append('/home/fred/public_html/cgi-bin/')
sys.path.append('/home/fred/public_html/cgi-bin/fredapp/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'fredapp.settings'

import django.core.handlers.wsgi

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

所以我的理解是,所有这一切意味着,如果有对domain.com/fredapp/的请求,则应通过django.wsgi将其移交给应用程序.但是,我得到的唯一答复是:

So my understanding is that all this means that if a request comes in for domain.com/fredapp/ that it should be turned over to the application via django.wsgi. However, the only response I get is:

[Fri Jan 22 18:46:08 2010] [error] [client xx.xxx.xx.xx] File does not exist: /home/fred/public_html/domain.com/500.shtml
[Fri Jan 22 18:46:08 2010] [error] [client xx.xxx.xx.xx] mod_wsgi (pid=26760): Exception occurred processing WSGI script '/home/fred/public_html/cgi-bin/fredapp/apache/django.wsgi'.
[Fri Jan 22 18:46:03 2010] [error] [client xx.xxx.xx.xx] File does not exist: /home/fred/public_html/domain.com/404.shtml
[Fri Jan 22 18:46:03 2010] [error] [client xx.xxx.xx.xx] File does not exist: /home/fred/public_html/domain

它在Linux上的Apache下运行.我尝试在服务器上的Python解释器中运行.wsgi脚本的每一行,但没有一个返回任何错误.我还尝试了sys.stdout = sys.stderr技巧,没有得到比上面更多的输出. 文件不存在"错误与站点的其余设置有关,并且在出现任何请求时都会发生.我还没有完成所有正确的设置(错误页面和索引页面等等),因为我只是想让应用程序本身运行.

This is running under Apache on Linux. I have tried running each line of the .wsgi script in the Python interpreter on the server, and none of them return any errors. I also tried the sys.stdout = sys.stderr trick and got no further output than what is above. The File does not exist errors have to do with the rest of the site's set-up and occur on any request. I haven't finished setting all that up properly (error pages and index pages and so on) because I'm just trying to get the app itself to run.

我已经在自己的机器上启动并运行了该应用程序,虽然不是以Daemon模式运行,但这是我的第一个Django应用程序,而且我认为托管服务提供商以前从未配置过该应用程序,因此我们重新飞了一点盲.如果有人有任何建议,我将不胜感激.谢谢!

I've gotten this app up and running under Apache on my own machine, though NOT in Daemon mode, but it's my first Django app, and I don't think my hosting provider has ever configured one before, so we're flying a little blind. If anyone has any suggestions, I'd be very grateful. Thank you!

推荐答案

如果引用的配置是您正在使用的配置,则错误实际上非常明显.你有:

If the quoted configuration about is what you are using, the error is rather obvious actually. You have:

WSGIDaemonProcess fred threads=15 display-name=%{GROUP} python-path=/home/fred/public_html/cgi-bin/fredapp/apache/
WSGIProcessGroup scratchf

应该是:

WSGIDaemonProcess fred threads=15 display-name=%{GROUP} python-path=/home/fred/public_html/cgi-bin/fredapp/apache/
WSGIProcessGroup fred

也就是说,进程组的名称必须匹配.

That is, the name of the process group must match.

您应该已经看到错误消息:

You should though have seen an error message:

No WSGI daemon process called 'scratchf' has been configured

这很可能早于记录的错误:

This would likely be before the logged error:

Exception occurred processing WSGI script

这就是为什么提供所有错误日志消息并且不要以为它们不相关很重要的原因.

This is why it is important that you supply all the error log messages and don't assume that they aren't relevant.

或者,您引用的配置与您正在使用的配置不同,或者不是所有配置.

Alternatively, you have quoted configuration different to what you are using or not all of the configuration.

更新1

您似乎已在Apache中启用了ErrorDocument指令,以将错误重定向到特定的URL.但是,因为您已经将Django安装在Web服务器的根目录中,并且没有将那些错误URL传递给Django,所以当生成错误时,Django会获取错误文档的重定向,但它无法解析URL并随后生成404.由于Apache看到了404错误页面重定向,因此它返回了500个默认错误页面.最终结果是真正的原始错误,所有信息都会丢失.

It looks like you may have ErrorDocument directive enabled in Apache to redirect errors to a specific URL. Because however you have mounted Django at root of web server and not excluded those error URLs from being passed through to Django, then when an error is generated Django gets the redirect for the error document but it cannot resolve the URL and subsequently generates a 404. Because Apache saw a 404 for error page redirect, it then returns a 500 default error page. The end result is that true original error and any information is lost.

因此,进入Apache配置并注释掉ErrorDocument指令.

Thus, go into Apache configuration and comment out the ErrorDocument directives.

更新2

将配置更改为:

WSGIScriptAlias /fredapp /home/fred/public_html/cgi-bin/fredapp/apache/django.wsgi

您不应在行上的第二个值后面加上斜线.错过了您实际上是尝试在子URL而不是Web服务器的根目录挂载.

You should not have trailing slash on the second value on line. Missed that you were actually trying to mount at sub URL and not at root of web server.

这篇关于无法解决Django安装程序中的mod_wsgi异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆