Lighttpd 运行 FastCGI 脚本挂起并出现 500 内部错误

Lighttpd 运行 FastCGI 脚本挂起并出现 500 内部错误

我正在尝试使用 lighttpd 和 fastcgi 来运行一个小型 flask 应用程序。当我尝试启动 lig​​httpd 时,它可以正常启动服务器,但是当我尝试在浏览器中连接时,它会挂起而没有给出任何有意义的错误消息。

我在 Raspberry Pi 3 上运行它。操作系统是 Raspbian Stretch Lite。

这是 lighttpd 日志输出。

2018-01-04 19:56:16: (log.c.217) server started
2018-01-04 19:56:19: (response.c.350) -- splitting Request-URI
2018-01-04 19:56:19: (response.c.351) Request-URI     :  /
2018-01-04 19:56:19: (response.c.352) URI-scheme      :  http
2018-01-04 19:56:19: (response.c.353) URI-authority   :  172.30.26.14
2018-01-04 19:56:19: (response.c.354) URI-path (raw)  :  /
2018-01-04 19:56:19: (response.c.355) URI-path (clean):  /
2018-01-04 19:56:19: (response.c.356) URI-query       :
2018-01-04 19:56:19: (response.c.350) -- splitting Request-URI
2018-01-04 19:56:19: (response.c.351) Request-URI     :  /application.fcgi/
2018-01-04 19:56:19: (response.c.352) URI-scheme      :  http
2018-01-04 19:56:19: (response.c.353) URI-authority   :  172.30.26.14
2018-01-04 19:56:19: (response.c.354) URI-path (raw)  :  /application.fcgi/
2018-01-04 19:56:19: (response.c.355) URI-path (clean):  /application.fcgi/
2018-01-04 19:56:19: (response.c.356) URI-query       :
2018-01-04 19:56:19: (response.c.490) -- before doc_root
2018-01-04 19:56:19: (response.c.491) Doc-Root     : /var/www/
2018-01-04 19:56:19: (response.c.492) Rel-Path     : /application.fcgi/
2018-01-04 19:56:19: (response.c.493) Path         :
2018-01-04 19:56:19: (response.c.542) -- after doc_root
2018-01-04 19:56:19: (response.c.543) Doc-Root     : /var/www/
2018-01-04 19:56:19: (response.c.544) Rel-Path     : /application.fcgi/
2018-01-04 19:56:19: (response.c.545) Path         : /var/www/application.fcgi/
2018-01-04 19:56:19: (response.c.562) -- logical -> physical
2018-01-04 19:56:19: (response.c.563) Doc-Root     : /var/www/
2018-01-04 19:56:19: (response.c.564) Basedir      : /var/www/
2018-01-04 19:56:19: (response.c.565) Rel-Path     : /application.fcgi/
2018-01-04 19:56:19: (response.c.566) Path         : /var/www/application.fcgi/
2018-01-04 19:56:19: (response.c.583) -- handling physical path
2018-01-04 19:56:19: (response.c.584) Path         : /var/www/application.fcgi/
2018-01-04 19:56:19: (response.c.745) -- after pathinfo check
2018-01-04 19:56:19: (response.c.746) Path         : /var/www/application.fcgi
2018-01-04 19:56:19: (response.c.747) URI          : /application.fcgi
2018-01-04 19:56:19: (response.c.748) Pathinfo     : /
2018-01-04 19:56:19: (response.c.753) -- handling subrequest
2018-01-04 19:56:19: (response.c.754) Path         : /var/www/application.fcgi
2018-01-04 19:56:19: (mod_fastcgi.c.3500) handling it in mod_fastcgi
2018-01-04 19:56:19: (mod_fastcgi.c.2875) got proc: pid: 8703 socket: unix:/tmp/fastcgi.socket-0 load: 1
^C2018-01-04 19:59:54: (server.c.1751) [note] graceful shutdown started
2018-01-04 19:59:55: (mod_fastcgi.c.2424) unexpected end-of-file (perhaps the fastcgi process died): pid: 8703 socket: unix:/tmp/fastcgi.socket-0
2018-01-04 19:59:55: (mod_fastcgi.c.3129) child exited, pid: 8703 status: 0
2018-01-04 19:59:55: (mod_fastcgi.c.3143) --- fastcgi spawning \n\tsocket unix:/tmp/fastcgi.socket-0 \n\tcurrent: 1 / 1
2018-01-04 19:59:55: (mod_fastcgi.c.900) new proc, socket: 0 /tmp/fastcgi.socket-0
2018-01-04 19:59:55: (mod_fastcgi.c.3175) response not received, request sent: 908 on socket: unix:/tmp/fastcgi.socket-0 for /application.fcgi?, closing connection
2018-01-04 19:59:55: (mod_fastcgi.c.1642) released proc: pid: 8710 socket: unix:/tmp/fastcgi.socket-0 load: 0
2018-01-04 20:00:01: (server.c.1626) connection closed - keep-alive timeout: 5
^C2018-01-04 20:00:01: (server.c.1828) server stopped by UID = 0 PID = 0

您可以看到我按下 CTRL C 来终止进程的位置。如您所见,我在此日志中找不到任何有意义的错误消息。此日志显示第一行2018-01-04 19:56:16: (log.c.217) server started,然后我转到浏览器中的 URL(即服务器的本地 IP)。但是,在我的浏览器中什么也没有发生,直到我终止该进程。然后我收到 500 内部服务器错误消息(在浏览器中)。

这是我的 fastcgi 脚本。

#!/usr/bin/python3
from flup.server.fcgi import WSGIServer
from modules import app

if __name__ == '__main__':
    WSGIServer(app).run()

这是我的 lighttpd.conf 文件。

server.modules   += ( "mod_fastcgi" )
server.modules   += ( "mod_rewrite" )
fastcgi.debug = 1
debug.log-request-handling = "enable"
debug.log-file-not-found = "enable"
server.username = "lighttpd"
server.groupname = "lighttpd"
server.document-root = "/var/www/"
server.port = 80
$SERVER["socket"] == ":80" {
    mimetype.assign = (
        ".html" => "text/html"
    )
    url.rewrite-once = (
    "^(/modules/static($|/.*))$" => "$1",
    "^(/.*)$" => "/application.fcgi$1"
    )
    $HTTP["host"] =~ "$" {
        server.document-root = "/var/www/"
        fastcgi.server = ( "application.fcgi" =>
         (( "socket" => "/tmp/fastcgi.socket",
            "bin-path" => "/home/pi/timeclock_venv/bin/python3 /var/www/TimeClock/application.fcgi",
            "max-procs" => 1,
           "bin-environment" => (
             "REAL_SCRIPT_NAME" => ""
           ),
           "check-local" => "disable"
         ))
         )
    }
}

在我的 lighttpd 脚本中,我使用 virtualenv 目录中的 python3 解释器,它具有我的 flask 应用程序所需的所有依赖项。

请给予我任何您认为必要的帮助或建议,以使其工作正常,谢谢。

更新

我发现,有时 lighttpd 确实会给我回溯,但这不是完整的回溯。以下是我得到的。

Traceback (most recent call last):
  File "/var/www/TimeClock/application.fcgi", line 3, in <module>
    from modules import app
  File "/var/www/TimeClock/modules/__init__.py", line 1, in <module>
    from flask import Flask
  File "/usr/local/lib/python3.5/dist-packages/flask/__init__.py", line 19, in <module>

相关内容