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



故事: 我用 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已安装(

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

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

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

最新更新