4

我试图让一些微不足道的 Django 在我的 Dreamhost 帐户上运行。在选择 Dreamhost 之前我确实做了功课,但直到最近才决定尝试 Django。

无论如何,我有一个简单的应用程序,我想在 something.mydomain.com 下运行。乘客已启用。

当我访问静态页面时,它可以正常加载,从 ~/something.mydomain.com/public/ 出来。当我访问任何其他页面(例如 something.mydomain.com/admin)时,该 url 应该由我的 Django 应用程序处理。

这就是我卡住的地方;页面没有加载,也没有抛出错误。它一直试图永远加载(还没有超时)。我对日志了解不多。我自己什么都没发现。

我的猜测是 ~/something.mydomain.com/ 中的passenger_wsgi.py 有问题。我试过不同的版本。

这位乘客给了……冻结?如上所述

import sys, os, django
sys.path.append("/home/me/something.mydomain.com/")
os.environ['DJANGO_SETTINGS_MODULE'] = 'something.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

这位乘客高兴地“你好,世界!”是我

import sys, os, django
sys.path.append("/home/me/something.mydomain.com/")
os.environ['DJANGO_SETTINGS_MODULE'] = 'something.settings'
def application(environ, start_response):
    write = start_response('200 OK', [('Content-type', 'text/plain')])
    return ["Hello, world!"]

所以我倾向于相信关于 WSGIHandler() 的某些东西没有得到适当的适应。

我在 python shell 中试过这个:

>>> import django

它没有给出任何错误。

现在怎么办?

4

4 回答 4

1

I gave up on using Django on Dreamhost because their server forcibly kills any wsgi process on a timed basis. After that a new request has to start a new instance, which in my case meant that queries sometimes took 10-15s. It was more than enough time for most people to assume the site was down and give up.

This might not be your particular problem, but I expect you will not be happy even if you do get your site working.

于 2010-11-23T00:38:05.183 回答
1

我能够使用Werkzeug模块为 WSGI 应用程序获得良好的调试设置。我认为这也可以与 Django 集成。

首先,我假设你在你的主目录下设置你的 python virtualenv~/env并且是活动的。

其次,安装werkzeug-debugger-appengine功能,修补werkzeug 调试器

cd ~
mkdir src
cd src
git clone https://github.com/nshah/werkzeug-debugger-appengine.git
cd werkzeug-debugger-appengine
python setup.py install

最后一步是设置您的passenger_wsgi.py文件:

import sys, os

DEBUG   = True
ROOT    = os.path.dirname(os.path.abspath(__file__))
INTERP  = '/home/HOMEDIR/env/bin/python'

sys.path.insert(1,ROOT)        # for when your app is in your web dir
if sys.executable != INTERP:
   os.execl(INTERP, INTERP, *sys.argv)

from myapp import app as application

if DEBUG:
   application.debug=True
   from werkzeug_debugger_appengine import get_debugged_app
   application = get_debugged_app(application)

不要忘记强制乘客重新启动:

touch ~/domain.com/tmp/restart.txt

现在,当您遇到异常时,您将获得如下所示的页面:

Werkzeug 调试器输出

于 2011-06-07T19:52:02.467 回答
0

我最初在DH上遇到了一系列与此类似的问题。我最终构建了自己的 Python 来代替他们的,并且从那以后没有任何问题。

设置一些路径:

echo 'PATH="$HOME/bin:$PATH"' >> ~/.bash_profile
echo 'LD_LIBRARY_PATH=$HOME/lib/' >> ~/.bash_profile
source ~/.bash_profile 

安装 Python:

wget http://python.org/ftp/python/2.7/Python-2.7.tgz
tar -xzvf Python-2.7.tgz
rm Python-2.7.tgz
cd Python-2.7
./configure --prefix=${HOME}
make
make install
cd ..
rm -rf Python-2.7 

并调整您的 WSGI 处理程序:

import sys, os
INTERP = "/home/example_user/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
sys.path.append("/home/example_user/example.com")
os.environ["DJANGO_SETTINGS_MODULE"] = "example_project.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
于 2011-03-10T22:26:59.143 回答
0

我同意 Ben 和 Chris 的观点,因为 DH 共享环境绝对不适合服务于大型项目。然而,Afaik 超时是基于上次加载的,所以如果你有稳定的流,你的应用程序应该 - 理论上! - 运行良好。:)

无论如何,我经常使用 DH 的共享乘客来进行概念验证,而且服务很好,价格也很优惠。

关于您的问题-Passenger 在捕获和解析 Rails 错误方面做得很好,但是当引发异常时,您用于 Django 的实验性 WSGI 实现会死掉。一种解决方法是运行一些中间件,它会捕获错误并将其传递给Passenger。

阅读更多详细信息和示例: http ://wiki.dreamhost.com/Passenger_WSGI#500_Errors_with_Passenger_WSGI_Workaround

于 2010-11-24T12:27:33.677 回答