lighttpd + webpy + fastCGI + python3 它是如何工作的?
lighttpd + webpy + fastCGI + python3 How it works?
故事:
我用 web.py 框架(一些解析器)编写了 python3 应用程序。我喜欢它,但它无法处理负载(10 个工人的一些限制)。我从 web.py 文档中找到了解决方案 - Webpy + LightTTPD with 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/"
)
还有我的"app"(实际上,如果我这样启动它,效果会很好: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()
当我尝试打开任何 link 时,我没有得到任何东西 - 只是加载页面,然后出现 500 错误。错误日志没有显示任何内容。
我应该先启动 fastCGI 还是 lighttpd 必须自己启动?我认为这部分 (fastcgi.server) 不起作用(flup 已经安装)
这是我刚从 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 中的一个错误,现在已修复?尝试更新它。
故事: 我用 web.py 框架(一些解析器)编写了 python3 应用程序。我喜欢它,但它无法处理负载(10 个工人的一些限制)。我从 web.py 文档中找到了解决方案 - Webpy + LightTTPD with 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/"
)
还有我的"app"(实际上,如果我这样启动它,效果会很好: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()
当我尝试打开任何 link 时,我没有得到任何东西 - 只是加载页面,然后出现 500 错误。错误日志没有显示任何内容。
我应该先启动 fastCGI 还是 lighttpd 必须自己启动?我认为这部分 (fastcgi.server) 不起作用(flup 已经安装)
这是我刚从 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 中的一个错误,现在已修复?尝试更新它。