使用 Passenger 部署 Django 应用程序
我可以浏览他们维基上的所有内容 - 然后我就迷失了。 http://wiki.dreamhost.com/Django
我有一个空白的 Django 模板,每当我尝试更改任何内容时,我都会得到一个500 内部服务器错误。
我已经在本地完全开发了我的 django 应用程序,只想在线托管它 - 我认为这很容易,但我慢慢地发现事实并非如此。
我将我的应用程序“视频”上传到此目录,然后将其放入已安装的应用程序中并运行“python manage.pysyncdb”,它没有找到固定装置(我发现很奇怪)。
从那里开始,它只会收到内部服务器错误。
这是我收到的错误: http://tweetune.com/ 这是错误日志:
[Wed Aug 24 01:49:15 2011] [error] [client 66.212.30.122] Premature end of script headers:
[Wed Aug 24 01:49:15 2011] [error] [client 66.212.30.122] Premature end of script headers: internal_error.html
[Wed Aug 24 08:16:40 2011] [error] [client 99.229.160.94] Premature end of script headers:
[Wed Aug 24 08:16:41 2011] [error] [client 99.229.160.94] Premature end of script headers: internal_error.html
[Wed Aug 24 08:21:38 2011] [error] [client 99.229.160.94] Premature end of script headers:
[Wed Aug 24 08:21:38 2011] [error] [client 99.229.160.94] Premature end of script headers: internal_error.html
[Wed Aug 24 08:27:41 2011] [error] [client 99.229.160.94] Premature end of script headers:
[Wed Aug 24 08:27:41 2011] [error] [client 99.229.160.94] Premature end of script headers: internal_error.html
我已经尝试了 6 个小时现在并无法弄清楚我做错了什么。我想我根本不明白如何部署应用程序 - 我现在的思考过程是采用本地托管的应用程序并在线替换默认 django 模板中的所有文件。我不明白为什么这不起作用,但事实并非如此。我通过在我的passenger_wdgi 文件中使用此代码尝试了“hello world app”示例,并且它有效...
def application(environ, start_response):
start_response('200 OK', [('Content-type', 'text/plain')])
return ["Hello, world!"]
任何方向都会有帮助。
编辑:这是我的passenger_wsgi.py文件的内容,可能会有所帮助(尽管它是由dreamhost自动生成的......所以认为它是正确的)。
import sys, os
sys.path.append(os.getcwd())
os.environ['DJANGO_SETTINGS_MODULE'] = "sotd.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
project_path='/home/tweettune.com/sotd/'
sys.path.insert(1, project_path)
I can get through everything on their wiki - and then I'm lost. http://wiki.dreamhost.com/Django
I have a blank Django template, and whenever I try to change anything I get a 500 internal server error.
I have completely developed my django app locally and just want to host it online - figured it would be easy but am slowly learning that it is not.
I upload my app "videos" to this directory and then put it into the installed apps and ran "python manage.py syncdb", which finds no fixtures (which I Found odd).
From there, it just gets an internal server error.
Here is the error I am getting: http://tweettune.com/ and here is the error log:
[Wed Aug 24 01:49:15 2011] [error] [client 66.212.30.122] Premature end of script headers:
[Wed Aug 24 01:49:15 2011] [error] [client 66.212.30.122] Premature end of script headers: internal_error.html
[Wed Aug 24 08:16:40 2011] [error] [client 99.229.160.94] Premature end of script headers:
[Wed Aug 24 08:16:41 2011] [error] [client 99.229.160.94] Premature end of script headers: internal_error.html
[Wed Aug 24 08:21:38 2011] [error] [client 99.229.160.94] Premature end of script headers:
[Wed Aug 24 08:21:38 2011] [error] [client 99.229.160.94] Premature end of script headers: internal_error.html
[Wed Aug 24 08:27:41 2011] [error] [client 99.229.160.94] Premature end of script headers:
[Wed Aug 24 08:27:41 2011] [error] [client 99.229.160.94] Premature end of script headers: internal_error.html
I've been trying for 6 hours now and can not figure out what I am doing wrong. I suppose I just don't understand how to deploy an application at all - my thought process now is take my locally hosted app and replace all the files in the default django template online. I don't see why this should not work but it's not. I tried the "hello world app" example by using this code in my passenger_wdgi file and it works...
def application(environ, start_response):
start_response('200 OK', [('Content-type', 'text/plain')])
return ["Hello, world!"]
Any direction would be helpful.
EDIT: Here are the contents of my passenger_wsgi.py file which may be helpful (although it is automatically generated by dreamhost...so figured it would be correct).
import sys, os
sys.path.append(os.getcwd())
os.environ['DJANGO_SETTINGS_MODULE'] = "sotd.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
project_path='/home/tweettune.com/sotd/'
sys.path.insert(1, project_path)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我也有同样的问题。
解决方案是将我的应用程序的文件夹添加到 wsgi_passenger.py
这个链接对我来说非常有用:
http://discussion.dreamhost.com/thread-128918.html
I had the same problem.
The solution was to add the folder of my application in the wsgi_passenger.py
This link was very useful to me:
http://discussion.dreamhost.com/thread-128918.html
如果使用 django>1.7 将最后一行替换为
If using django>1.7 replace two last line with
如果不查看您的设置,就很难准确地知道您做错了什么。我按照说明进行操作,这并不难。
调试应用程序可以做的一件事是运行manage.py。它无法绑定到套接字(如果绑定到套接字,它会在几分钟后自动终止),但这至少会显示是否存在其他问题阻止您的应用程序运行。
另一件需要注意的事情是:该文件名为
passenger_wsgi.py
,并且应该位于您的站点根目录中。例如,我有~/testing.tustincommercial.com/passenger_wsgi.py
,并且我的所有项目代码都位于~/testing.tustincommercial.com/oneclickcos
下。我的静态内容位于~/testing.tustincommercial.com/public
下。安装一些错误处理中间件会有所帮助,这样错误就不会一路传播给乘客,从而触发 500 错误。
我的
wsgi_passenger.py
是:这做了很多事情,其中大部分并不是绝对必要的 - 顶部的所有内容都是为了确保我安装的库可用。底部的东西安装中间件。你可能最好使用paste.exceptions.errormiddleware.ErrorMiddleware,除非werkzeug调试器适合你(它在Dreamhost上不适合我)。
编辑:我认为你的配置是错误的。请转到包含您的项目的目录,并使用
pwd
获取完整路径。我想你会发现你的路没有走对。It's difficult to know exactly what you're doing wrong without seeing your setup. I followed the instructions, and it wasn't that hard.
One thing you can do to debug your application is to run through manage.py. It won't be able to bind to a socket (and if it does, it will get autokilled after a few minutes), but that will at least show if there are other problems that prevent your app from running.
One other thing to note: the file is called
passenger_wsgi.py
, and should live in your site root. For example, I have~/testing.tustincommercial.com/passenger_wsgi.py
, and all of my project code lives under~/testing.tustincommercial.com/oneclickcos
. My static content lives under~/testing.tustincommercial.com/public
.It can help to have some error-handling middleware installed, so that errors don't propagate all the way to passenger, thus triggering a 500 error.
My
wsgi_passenger.py
is:This does a bunch of stuff, most of which isn't strictly necessary - all of the stuff at the top is to make sure that the libraries I've installed are available. The stuff at the bottom installs middleware. You're probably better off with
paste.exceptions.errormiddleware.ErrorMiddleware
, unless the werkzeug debugger works for you (it won't work for me on Dreamhost).Edit: I think your config is wrong. Please go the directory which holds your project, and use
pwd
to get the full path. I think you will find you have not got your paths right.我遇到了完全相同的问题。这里的答案让我找到了正确的方向,谢谢。我将 virtualenv 与我的 django 应用程序一起使用,并且 os.getcwd() 为我做到了。
I had the exact same problem. The answers here put me in the right direction, thanks. I use virtualenv with my django app and the os.getcwd() did it for me.