代码之家  ›  专栏  ›  技术社区  ›  Alexander Rainchik

lighttpd+webpy+fastcgi+python3工作原理?

  •  0
  • Alexander Rainchik  · 技术社区  · 6 年前

    Story: 我用web.py框架(一些解析器)编写了python3应用程序。我喜欢它,但它不能处理负载(一些限制为10名工人)。我从web.py文档中找到了解决方案-webpy+lightttpd和fastcgi。

    当我尝试使用它并在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"
    )
    

    还有我的“应用程序”(实际上,如果我像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 回复  |  直到 6 年前
        1
  •  0
  •   Jeronimo    6 年前

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

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

    它不同于 TypeError 从上面可以看到你。也许这只是webpy旧版本中的一个bug,现在已经修复了?尝试更新它。