【问题标题】:lighttpd + webpy + fastCGI + python3 How it works?lighttpd + webpy + fastCGI + python3 它是如何工作的?
【发布时间】:2018-11-09 13:08:25
【问题描述】:

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

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

     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)

【问题讨论】:

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


    【解决方案1】:

    这是我刚刚从 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 中的一个错误,现在已修复?尝试更新它。

    【讨论】:

    • 是的,完美。我从 pip 安装 - 没有最后的修复。现在可以了。
    猜你喜欢
    • 1970-01-01
    • 2013-01-17
    • 2016-07-16
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多