簡體   English   中英

Django lighttpd FCGI錯誤

[英]Django lighttpd FCGI error

我試圖通過lighttpd + fcgi部署我的django應用程序,但是當我運行fcgi腳本時,它給了我一個錯誤

這是fcgi腳本本身:

#!/usr/bin/python2.6
import sys, os

# Add a custom Python path.
sys.path.insert(0, "/home/wite")

# Switch to the directory of your project. (Optional.)
os.chdir("/home/wite/dormcode")

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "dormcode.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

當用python運行fcgi腳本時,我得到了302 FOUND 當我嘗試通過網絡瀏覽器訪問該頁面時,我什么都沒得到。

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 302 FOUND
Vary: Cookie
Content-Type: text/html; charset=utf-8
Location: http://localhost/login/
Set-Cookie:  csrftoken=30f07d4a59820a5ab7b502447cc16f5a; Max-Age=31449600; Path=/

* 編輯*

在玩了一些lighttpd配置選項之后,我設法得到了一些不同的東西。 當我通過網絡瀏覽器訪問該應用程序時,該頁面會掛起一段時間並出現500錯誤,將其保留在日志中:

2011-02-12 01:04:59: (mod_fastcgi.c.2582) unexpected end-of-file (perhaps the fastcgi process died): pid: 0 socket: tcp:127.0.0.1:80 
2011-02-12 01:04:59: (mod_fastcgi.c.3367) response not received, request sent: 1076 on socket: tcp:127.0.0.1:80 for /dormcode.fcgi?, closing connection

除此之外還有更多的東西。

payne是正確的,因為這個fastcgi監聽器使用stdin作為其通信套接字。

但是,這只是運行FastCGI響應器的方法之一 事實上,這是為lighttpd運行響應程序的錯誤方法,因為lighttpd不支持通過stdin與其響應程序通信。

關鍵在於這一行:

runfastcgi(method="threaded", daemonize="false")

這是apache的正確行,但不是lighttpd的正確行。 對於lighttpd,你想要這樣的東西:

runfastcgi(method="prefork", daemonize="true", host="127.0.0.1", port="3033")

這樣做是在你選擇的主機/端口上運行fastcgi進程,作為一個守護進程,它將分叉到后台。 設置daemonize =“false”進行調試,或者如果使用supervisord東西,但大多數人通常都想要一個守護進程。

應該注意的是,如果您的腳本與剛剛粘貼的腳本一樣簡單,則不需要整個腳本。 您可以通過manage.py運行fastCGI響應器:

./manage.py runfcgi method=prefork host=127.0.0.1 port=3033 pidfile=/path/to/foo.pid

既然你(希望)讓你的FastCGI響應器運行,你想在lighttpd配置中這樣做:

"/mysite.fcgi" => (
    "main" => (
         "host" => "127.0.0.1",
         "port" => 3033,
          "check-local" => "disable",
    )
),

也就是說,無論你為fastcgi響應者選擇什么端口,都需要指向lighttpd。

應該注意的是,所有這些都可以在Django FastCGI文檔中找到,但是這個文檔通過頻繁編輯和開源項目中的一些功能蠕變而失去了很多清晰度。

首先,使用sh您嘗試將腳本作為shell腳本運行,而不是Python程序。 如果你真的想把它作為python程序運行,輸入python /home/wite/code/code.fcgi

其次,請記住FastCGI應用程序作為deamons運行 - 您仍然需要一個Web服務器來連接到您從這里開始的進程。

最后,如果您嘗試手動測試此FastCGI程序:這並不總是有用,因為FastCGI在Web服務器和您的應用程序之間的stdin和stdout上使用特殊協議。 (您可以通過這種方式測試CGI腳本,因為CGI更簡單)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM