我正在尝试使用 fastcgi 将简单的 flask 脚本部署到 lighttpd 服务器。
这是使用 flask 文档构建的 lighttpd 配置文件http://flask.pocoo.org/docs/deploying/fastcgi/#configuring-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 pos: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.
答案1
您需要用 来关闭 url.rewrite )
。
该 fcgi 错误似乎与一个 fcgi 脚本有关,但您的配置片段中并未提及该脚本。这是整个配置吗?conf.enabled 目录中是否有任何内容?
答案2
如果您使用 lighttpd(fastcgi.server 块中的 bin-path 选项)生成 fcgi-app,则 fcgi-app 不能使用套接字名称(lighttpd 会将套接字绑定到 fcgi-app 的 STDIN,并且 fcgi-app 通常会检测到这一点)。