Search code examples
pythonfastcgilighttpdgevent

Setup gevent with Lighttpd, weird stuff


I have wary odd problem. I configured Lighttpd to pass /test to fastcgi backend. just added this in config

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

Now, when i start flup example, and hit 127.0.0.1:80/test everything work fine. Tested uWSGI to, still fine.

flup example:

#!/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()

Now, only problem is when I start gevent it won't work. Lighttpd mod_fastcgi says that backend just blocked.

Funny part is when I alter handler to return just string, cause WSGI require iterable, and hit 127.0.0.1:7101 from my browser it work as expected. This should be WSGIServer, how can it work this way?

Here is gevent code:

#!/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()

Bottom line is , why only gevent wont work in this setup, and both flup and uWSGI are working? Is there some secret setting not mention in official example here.


Solution

  • Because gevent.wsgi.WSGIServer is not a fcgi server, it's only http server. Your can proxy your requests from lighttpd to gevent as http, or use wsgi.