Python

燒瓶,使用 fastcgi 的 lighttpd 無法正常工作

  • July 3, 2013

我正在嘗試將一個簡單的燒瓶腳本部署到帶有 fastcgi 的 lighttpd 伺服器。

這是使用燒瓶文件http://flask.pocoo.org/docs/deploying/fastcgi/#configuring-lighttpd建構的 lighttpd 的配置文件

server.modules = ( 
       "mod_access",
       "mod_alias",
       "mod_compress",
       "mod_redirect",
       "mod_rewrite",
       "mod_fastcgi",
)

server.document-root        = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"

index-file.names            = ( "index.php", "index.html",
                               "index.htm", "default.htm",
                              " index.lighttpd.html" )

url.access-deny             = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

var.home_dir = "/var/lib/lighttpd"
var.socket_dir = home_dir + "sockets/"
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl"

dir-listing.encoding        = "utf-8"
server.dir-listing          = "enable"

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/x-javascript", "text/css", "text/html", "text/plain" )

include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"


fastcgi.server = ("weibo/callback.fcgi" =>
   ((  
       "socket" => "/tmp/weibocrawler-fcgi.sock",
       "bin-path" => "/var/www/weibo/callback.fcgi",
       "check-local" => "disable",
       "max-procs" => 1
   ))  
)

url.rewrite-once = ( 
   "^(/weibo($|/.*))$" => "$1",
   "^(/.*)$" => "weibo/callback.fcgi$1"

這是我要執行的腳本:

#!/home/nrl/kuro/weiboenv/bin/python
from flup.server.fcgi import WSGIServer
from callback import app 

if __name__ == '__main__':
   WSGIServer(application, bindAddress='/tmp/weibocrawler-fcgi.sock').run()

但我在測試配置文件時遇到此錯誤我收到此錯誤:2013-07-02 17:15:42: (configfile.c.912) 來源:lighttpd.conf.new 行:52 位置:1 解析器在此處附近以某種方式失敗: weibo/callback.fcgi$1

當我刪除 urlrewrite 時,即使守護程序啟動,我也會在日誌中收到這些錯誤:

2013-07-02 16:25:53: (log.c.166) server started 
2013-07-02 16:25:53: (mod_fastcgi.c.1104) the fastcgi-backend fcgi.py failed to start: 
2013-07-02 16:25:53: (mod_fastcgi.c.1108) child exited with status 2 fcgi.py 
2013-07-02 16:25:53: (mod_fastcgi.c.1111) If you're trying to run your app as a FastCGI backend, make sure you're using the FastCGI-enabled version.
If this is PHP on Gentoo, add 'fastcgi' to the USE flags. 
2013-07-02 16:25:53: (mod_fastcgi.c.1399) [ERROR]: spawning fcgi failed. 
2013-07-02 16:25:53: (server.c.938) Configuration of plugins failed. Going down.

你需要用 .rewrite 關閉 url.rewrite )

該 fcgi 錯誤似乎是指我在您的配置片段中沒有提到的 fcgi 腳本。這是整個配置嗎?conf.enabled 目錄中有什麼東西嗎?

如果您使用 lighttpd(fastcgi.server 塊中的 bin-path 選項)生成 fcgi-app,則 fcgi-app 不得使用套接字名稱(lighttpd 會將套接字綁定到 fcgi-app 的 STDIN,並且 fcgi-應用程序通常會檢測到這一點)。

引用自:https://serverfault.com/questions/520374