lighttpd + webpy + fastCGI + python3它是如何工作的?

时间:2018-05-30 15:41:04

标签: python-3.x fastcgi lighttpd web.py

故事: 我用web.py框架(一些解析器)编写了python3应用程序。我喜欢它,但它无法处理负载(10个工人的一些限制)。我从web.py文档中找到了解决方案 - 使用FastCGi的Webpy + LightTTPD。

当我尝试使用它并使用python3应用程序启动lighttpd时出现错误:

     File "code.py", line 18, in <module>
if __name__ == '__main__':application.run()
File "/usr/local/lib/python3.6/site-packages/web/application.py", line 341, in run
return wsgi.runwsgi(self.wsgifunc(*middleware))
File "/usr/local/lib/python3.6/site-packages/web/wsgi.py", line 34, in runwsgi
or 'SERVER_SOFTWARE') in os.environ:
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_collections_abc.py", line 666, in __contains__
self[key]
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py", line 666, in __getitem__
value = self._data[self.encodekey(key)]
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py", line 744, in encode
raise TypeError("str expected, not %s" % type(value).__name__)
TypeError: str expected, not bool

接下来,我尝试了python2应用程序,这是lighttpd.conf:

server.modules              = (
        "mod_access",
        "mod_alias",
        "mod_accesslog",
        "mod_compress"
        )

server.port = 8081
server.document-root = "/python/metrics_interlayer/"
server.errorlog = "/python/metrics_interlayer/light_error.log"
accesslog.filename          =    "/python/metrics_interlayer/light_access.log"

server.modules += ("mod_fastcgi", "mod_rewrite")

fastcgi.server = ( "/code.py" =>
(
"python-fcgi" =>
(
  "socket" => "/tmp/fastcgi.python.socket",
  "bin-path" => "/python/metrics_interlayer/code.py",
  "max-procs" => 1
))
)

url.rewrite-once = (
 "^/(.*)$" => "/code.py/$1"
)

我的&#34; app&#34;(实际上,如果我启动它会很好:python code.py):

    #!/usr/bin/env python

    import web

    urls = ('/(.*)', 'Index')

    application = web.application(urls, globals())
    web.config.debug = True

    class Index:

        def GET(self, name=''):
            return 'Hello World'

        def POST(self, name=''):
            return 'Hello World'

    if __name__ == '__main__':application.run()

当我尝试打开任何链接时,我什么也得不到 - 只是加载页面然后得到500错误。错误日志不显示任何内容。

我以前应该启动fastCGI还是lighttpd必须自己启动?我认为这部分(fastcgi.server)不起作用(已经安装了flup)

1 个答案:

答案 0 :(得分:0)

以下是我刚从http://webpy.org/下载的web / wsgi.py中的第33和34行:

if (os.environ.has_key('PHP_FCGI_CHILDREN') #lighttpd fastcgi
  or os.environ.has_key('SERVER_SOFTWARE')):

它与您上面的TypeError显示的不同。也许这只是旧版webpy中的一个错误,现在已经修复了?尝试更新它。