【问题标题】:Setup gevent with Lighttpd, weird stuff使用 Lighttpd 设置 gevent,奇怪的东西
【发布时间】:2012-08-05 16:27:07
【问题描述】:

我有一个奇怪的问题。我将 Lighttpd 配置为将 /test 传递给 fastcgi 后端。 刚刚在配置中添加了这个

fastcgi.server = ("/test" =>
  ("127.0.0.1" =>
    (
      "host" => "127.0.0.1",
      "port" => 7101,
      "docroot" => "/",
      "check-local" => "disable"
    )
  )
)

现在,当我启动 Flup 示例并点击 127.0.0.1:80/test 时,一切正常。测试 uWSGI 到,还是可以的。

flup 示例:

#!/usr/bin/env python
from flup.server.fcgi import WSGIServer

def myapp(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Hello World']

WSGIServer(myapp, bindAddress = ('127.0.0.1',7101)).run()

现在,唯一的问题是当我启动 gevent 时它不起作用。 Lighttpd mod_fastcgi 说后端刚刚被阻塞。

有趣的是,当我更改处理程序以仅返回字符串时,导致 WSGI 需要可迭代,并从我的浏览器中点击 127.0.0.1:7101,它按预期工作。这应该是WSGIServer,怎么会这样呢?

这里是gevent代码:

#!/usr/bin/python
"""WSGI server example"""
from gevent.wsgi import WSGIServer

def app(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    #return ["Hello World", StopIteration]   # this is WSGI test, not working
    return "Hello World"
    # when set like this, frontend :80 still wont work (500 Internal error), 
    # but 127.0.0.1:7101 work like standard http

if __name__ == '__main__':
    WSGIServer(('', 7101), app).serve_forever()

底线是,为什么只有 gevent 在这个设置中不起作用,而 Flup 和 uWSGI 都在起作用?有没有官方例子here没有提到的一些秘密设置。

【问题讨论】:

    标签: python fastcgi lighttpd gevent


    【解决方案1】:

    因为 gevent.wsgi.WSGIServer 不是 fcgi 服务器,它只是 http 服务器。您可以将您的请求从 lighttpd 代理到 gevent 作为 http,或使用 wsgi。

    【讨论】:

    • 嗯,我需要 fcgi 来进行负载平衡。看不懂,官方文档和例子都说是WSGI服务器看这里bitbucket.org/denis/gevent/src/tip/examples/wsgiserver.py#cl-4
    • 我认为这意味着,它是为处理程序提供 wsgi 接口的服务器:environ、start_response 等。
    • 如果你需要 gevent 和 fcgi,你可以使用 uwsgi 和 gevent-loop。
    【解决方案2】:

    你可以看到 Flup here 声明它 SPEAK FastCGI (not HTTP),而 uWSGI here 声明“作为一个 WSGI-only 服务器而生”。 现在 Gevent 说here“基于 libevent-http 的快速 WSGI 服务器”,这让我很困惑,但后来我尝试了 gunicorn,但它失败了。 然后我发现here“Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX”。这意味着 gevent 和 gunicorn WSGI 处理程序是 HTTP 请求不是 FastCGI,但正如 Fedor Gogolev 所说,对于您的处理程序它们是 WSGI 服务器。

    所以对于 FlupuWSGI,你需要配置 lighttpd(或任何其他网络服务器)以使用 fastcgi 模块,但对于 gunicorn gevent 你使用 proxy 模块,对他们来说你根本不需要使用前端!如果没有静态的东西来服务或其他你可以省略前端原因 gunicorn 状态它是谨慎快速和稳定的。

    【讨论】:

      猜你喜欢
      • 2017-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-11
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      • 2020-11-02
      相关资源
      最近更新 更多