I'm trying to get some trivial Django to run on my dreamhost account. I did do my homework before choosing Dreamhost, but only recently decided to try Django.
Anyhow, I have a trivial app that I want to run under something.mydomain.com. Passenger is enabled.
When I visit a static page, it loads fine, out of ~/something.mydomain.com/public/. When I visit any other page (such as something.mydomain.com/admin), the url should be handled by my Django app.
This is where I get stuck; the page doesn't load and it doesn't throw an error. It keeps trying to load forever (no timeout yet). I don't know much about the logs; I haven't found anything myself.
My guess is the passenger_wsgi.py in ~/something.mydomain.com/ is faulty. I have tried different versions.
This passenger gives the… freeze? described above
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()
This passenger happily "Hello, world!"s me
import sys, os, django
sys.path.append("/home/m开发者_开发知识库e/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!"]
So I'm inclined to believe something about WSGIHandler() isn't properly accomodated.
I tried this in a python shell:
>>> import django
and it gave no errors.
What now?
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.
I was able to get a good debug setup for WSGI app using Werkzeug module. I think this can also be integrated with Django.
First, I'll assume you setup your python virtualenv in your home directory under ~/env
and is active.
Second, install the werkzeug-debugger-appengine functions, to patch the werkzeug debugger.
cd ~
mkdir src
cd src
git clone https://github.com/nshah/werkzeug-debugger-appengine.git
cd werkzeug-debugger-appengine
python setup.py install
The final step is to setup your passenger_wsgi.py
file:
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)
Don't forget to force passenger to restart:
touch ~/domain.com/tmp/restart.txt
Now, when you hit an exception, you'll get a page that looks like this:
I agree with Ben and Chris, in that DH shared env is definitely not suitable for serving larger projects. Afaik, however, the timeout is based on last load, so if you have a steady stream your app should -in theory!- run fine. :)
Anyway, I use DH's shared Passenger for proof of concept a lot, and there is serves well, for a very good price.
About your issue - Passenger is doing a good job catching and parsing Rails errors, but the experimental WSGI implementation you use for Django dies when an exception is raised. A workaround is to run some middleware, that catches the error and passes it on nicely rendered to Passenger.
Read for more details and an example: http://wiki.dreamhost.com/Passenger_WSGI#500_Errors_with_Passenger_WSGI_Workaround
I had a series of problems similar to this on DH originally. I ended up building my own Python to use instead of theirs and haven't had any problems since.
Setup some paths:
echo 'PATH="$HOME/bin:$PATH"' >> ~/.bash_profile
echo 'LD_LIBRARY_PATH=$HOME/lib/' >> ~/.bash_profile
source ~/.bash_profile
Install 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
and to adjust your WSGI handler:
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()
精彩评论