2011-08-24 68 views
8

我可以通過他們的wiki上的所有內容 - 然後我迷路了。 http://wiki.dreamhost.com/Django使用乘客部署Django應用

我有一個空白的Django模板,每當我嘗試更改任何內容時,我都會收到500內部服務器錯誤。

我已經完全在本地開發了我的django應用程序,只是想在網上託管 - 認爲這很容易,但我慢慢發現它不是。

我上傳我的應用程序「視頻」到這個目錄,然後把它放入已安裝的應用程序並運行「python manage.py syncdb」,它找不到任何燈具(我發現奇怪)。

從那裏,它只是得到一個內部服務器錯誤。

這裏是我得到的錯誤:http://tweettune.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應用程序」的例子,它的工作原理...

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) 
+0

最後兩行顯示您的配置文件。 –

+0

對不起,我不確定你的配置文件是什麼意思? passenger_wsgi.py內容?請原諒我對這個問題的無知 - 第一次嘗試部署一個項目。 – brandonmat

+0

我認爲你的路徑錯了。導航到shell中的項目目錄,並使用'pwd'打印該目錄的全名。 – Marcin

回答

1

在看不到您的設置的情況下很難確切知道您做錯了什麼。我遵循指示,並沒有那麼難。

您可以通過manage.py來執行調試應用程序的一件事。它將無法綁定到套接字(如果有,它會在幾分鐘後自動激活),但至少會顯示是否有其他問題阻止您的應用程序運行。

還有一件事要注意:該文件被稱爲passenger_wsgi.py,並且應該位於您的網站根目錄中。例如,我有~/testing.tustincommercial.com/passenger_wsgi.py,我的所有項目代碼都在~/testing.tustincommercial.com/oneclickcos之下。我的靜態內容在~/testing.tustincommercial.com/public之下。

它可以幫助安裝一些錯誤處理中間件,以便錯誤不會傳播給乘客,從而觸發500錯誤。

wsgi_passenger.py是:

import sys, os, re 
cwd = os.getcwd() 
sys.path.append(os.getcwd()) 

#add all installed eggs to path 
for x in ['/home/marcintustin/django/'+x for x in os.listdir('/home/marcintustin/django/') if re.search('egg$', x)]: 
    sys.path.insert(0,x) 

sys.path.insert(0,'/home/marcintustin/django') 
sys.path.insert(0,'/home/marcintustin/django/Django-1.3') 
sys.path.insert(0,'/home/marcintustin/django/Paste-1.7.5.1-py2.5.egg') 
sys.path.insert(0,'/home/marcintustin/django/South-0.7.3-py2.5.egg') 
sys.path.insert(0,'/home/marcintustin/django/Werkzeug-0.6.2-py2.5.egg') 

myapp_directory = cwd + '/oneclickcos' 
sys.stdout = sys.stderr 
sys.path.insert(0,myapp_directory) 
sys.path.append(os.getcwd()) 

os.environ['DJANGO_SETTINGS_MODULE'] = "oneclickcos.settings" 
import django.core.handlers.wsgi 
#from paste.exceptions.errormiddleware import ErrorMiddleware 
from werkzeug.debug import DebuggedApplication 
from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException 

application = django.core.handlers.wsgi.WSGIHandler() 
handler = AdminMediaHandler(application, '/home/marcintustin/testing.tustincommercial.com/public/static/admin') 
application = DebuggedApplication(handler, evalex=True) 

這做了一堆東西,其中大部分是不是絕對必要的 - 所有的頂部的東西,以確保我已經安裝了庫可用。最底層的東西安裝中間件。除非werkzeug調試器適用於你,否則你可能更適合使用paste.exceptions.errormiddleware.ErrorMiddleware(在Dreamhost上它不適用於我)。

編輯:我認爲你的配置是錯誤的。請轉到保存項目的目錄,並使用pwd獲取完整路徑。我想你會發現你沒有正確的道路。

+0

我想我有一個問題。如果我的設置出現問題,或者它是否會將500服務器錯誤恢復,我是否會希望看到正常的django調試錯誤? – brandonmat

+0

500錯誤可能是由代碼中的異常傳播到頂部或由於配置有問題導致的。安裝中間件的目的是捕獲並顯示代碼中出現的異常。所以,錯誤的配置會導致500錯誤,但它不是唯一可能的來源。 – Marcin

+0

PWD迴應 - /home/brandonmattalo/tweettune.com 和我的django項目本身是/home/brandonmattalo/tweettune.com/sotd – brandonmat

7

我有同樣的問題。 解決的辦法是增加我的應用程序的文件夾中的wsgi_passenger.py

import sys, os 
sys.path.append(os.getcwd()) 
sys.path.append(os.path.join(os.getcwd(), 'include your apps folder here')) 
os.environ['DJANGO_SETTINGS_MODULE'] = "cpc.settings" 
import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

這個環節是非常有用的對我說: http://discussion.dreamhost.com/thread-128918.html

0

我有完全相同的問題。這裏的答案讓我朝着正確的方向,謝謝。我使用virtualenv與我的django應用程序和os.getcwd()爲我做了。

import os, sys 

#Fix for passenger 
INTERP = "/var/webapps/myapp_env/bin/python" 
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv) 
sys.path.append(os.getcwd()) 
# 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings") 
from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application() 
7

如果使用Django> 1.7替換

from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application()