Skip to main content
 首页 » 编程设计

python之如何使用 flup/python 配置 lighttpd bin-path 参数

2025年05月04日6zlslch

我在带有 Flup 1.0.3 开发版的 Ubuntu 10.04 上运行 lighttpd 1.4.26。

设置 mod_fastcgi 时,如果我在启动 lig​​httpd 之前手动启动 fcgi(作为 www-data),我可以成功地让 lighttpd 与本地套接字上的 fcgi 进程通信。

sudo su www-data 
/webapps/test/test.fcgi 

然后在另一个shell中...

sudo /etc/init.d/lighttpd/start 

当我尝试使用 fastcgi.server 配置中的 bin-path 参数自动启动该进程时,该进程启动了,但未成功与该进程通信。

我已将 lighttpd\error.log 中的消息隔离为以下内容:

成功(手动启动):

2012-01-03 11:56:52: (mod_fastcgi.c.3647) handling it in mod_fastcgi 
2012-01-03 11:56:52: (response.c.468) -- before doc_root 
2012-01-03 11:56:52: (response.c.469) Doc-Root     : /webapps/test 
2012-01-03 11:56:52: (response.c.470) Rel-Path     : /test.fcgi 
2012-01-03 11:56:52: (response.c.471) Path         : 
2012-01-03 11:56:52: (response.c.519) -- after doc_root 
2012-01-03 11:56:52: (response.c.520) Doc-Root     : /webapps/test 
2012-01-03 11:56:52: (response.c.521) Rel-Path     : /test.fcgi 
2012-01-03 11:56:52: (response.c.522) Path         : /webapps/test/test.fcgi 
2012-01-03 11:56:52: (configfile-glue.c.583) === start of condition block === 
2012-01-03 11:56:52: (configfile-glue.c.541) 1 (cached) result: false 
2012-01-03 11:56:52: (configfile-glue.c.583) === start of condition block === 
2012-01-03 11:56:52: (configfile-glue.c.541) 2 (cached) result: false 
2012-01-03 11:56:52: (response.c.539) -- logical -> physical 
2012-01-03 11:56:52: (response.c.540) Doc-Root     : /webapps/test 
2012-01-03 11:56:52: (response.c.541) Rel-Path     : /test.fcgi 
2012-01-03 11:56:52: (response.c.542) Path         : /webapps/test/test.fcgi 
2012-01-03 11:56:52: (mod_fastcgi.c.3071) got proc: pid: 0 socket: unix:/tmp/fcgi.sock load: 1 
2012-01-03 11:56:52: (connections.c.1773) state at exit: 7 handle-req 
2012-01-03 11:56:52: (mod_fastcgi.c.1492) released proc: pid: 0 socket: unix:/tmp/fcgi.sock load: 0 
2012-01-03 11:56:52: (connections.c.1367) state at start 7 handle-req 
2012-01-03 11:56:52: (connections.c.1431) state for fd 7 handle-req 
2012-01-03 11:56:52: (connections.c.1511) state for fd 7 resp-start 
2012-01-03 11:56:52: (response.c.128) Response-Header: 
HTTP/1.1 200 OK^M 
Content-Type: text/plain^M 
Content-Length: 13^M 
Date: Tue, 03 Jan 2012 19:56:52 GMT^M 
Server: lighttpd/1.4.26^M 

不成功:

2012-01-03 11:53:17: (mod_fastcgi.c.3647) handling it in mod_fastcgi 
2012-01-03 11:53:17: (response.c.468) -- before doc_root 
2012-01-03 11:53:17: (response.c.469) Doc-Root     : /webapps/test 
2012-01-03 11:53:17: (response.c.470) Rel-Path     : /test.fcgi 
2012-01-03 11:53:17: (response.c.471) Path         : 
2012-01-03 11:53:17: (response.c.519) -- after doc_root 
2012-01-03 11:53:17: (response.c.520) Doc-Root     : /webapps/test 
2012-01-03 11:53:17: (response.c.521) Rel-Path     : /test.fcgi 
2012-01-03 11:53:17: (response.c.522) Path         : /webapps/test/test.fcgi 
2012-01-03 11:53:17: (configfile-glue.c.583) === start of condition block === 
2012-01-03 11:53:17: (configfile-glue.c.541) 1 (cached) result: false 
2012-01-03 11:53:17: (configfile-glue.c.583) === start of condition block === 
2012-01-03 11:53:17: (configfile-glue.c.541) 2 (cached) result: false 
2012-01-03 11:53:17: (response.c.539) -- logical -> physical 
2012-01-03 11:53:17: (response.c.540) Doc-Root     : /webapps/test 
2012-01-03 11:53:17: (response.c.541) Rel-Path     : /test.fcgi 
2012-01-03 11:53:17: (response.c.542) Path         : /webapps/test/test.fcgi 
2012-01-03 11:53:17: (mod_fastcgi.c.3071) got proc: pid: 23117 socket: unix:/tmp/fcgi.sock-0 load: 1 
2012-01-03 11:53:17: (connections.c.1773) state at exit: 7 handle-req 
2012-01-03 11:53:27: (connections.c.1367) state at start 8 error 
2012-01-03 11:53:27: (connections.c.1746) shutdown for fd 8 
2012-01-03 11:53:27: (connections.c.1598) state for fd 8 close 
2012-01-03 11:53:27: (connections.c.1621) connection closed for fd 8 
2012-01-03 11:53:27: (connections.c.1587) state for fd 8 connect 
2012-01-03 11:53:27: (connections.c.1773) state at exit: 8 connect 

我的 fastcgi 配置:

server.modules   += ( "mod_fastcgi" ) 
 
## Start an FastCGI server 
fastcgi.debug = 1 
 
fastcgi.server    = ( ".fcgi" => 
                      ( "localhost" => 
                        ( 
                        "socket" => "/tmp/fcgi.sock", 
                        #"bin-path" => "/webapps/test/test.fcgi", 
                        "max-procs" => 1, 
                        "check-local" => "disable" 
                                        ) 
                                      ) 
                                ) 

我所做的唯一更改是取消注释 bin-path 行以直接引用 fcgi 文件。

fcgi文件的内容只是一个简单的hello world:

#!/usr/bin/python2.6 
 
from flup.server.fcgi import WSGIServer 
 
def myapp(environ, start_response): 
    print 'got request: %s' % environ 
    start_response('200 OK', [('Content-Type', 'text/plain')]) 
    return ['Hello World!\n'] 
 
WSGIServer(myapp, bindAddress = '/tmp/fcgi.sock').run() 

我是 lighttpd 的新手,所以也许我遗漏了一些简单的东西。提前致谢!

请您参考如下方法:

我在使用 flup 安装 lighttpd 和 Django 时遇到了同样的问题。 通过为套接字文件 xxx.sock-0 而不是像以前的 xxx.sock 设置 flup 解决了这个问题。 它也可能对您有用。

看起来有点乱。我不是 Linux 专家,可能其他人会提供解决方案。