0

I'm attempting to use lighttpd and fastcgi to run a small flask application. When I try to start lighttpd, it starts the server just fine, but when I try to connect in the browser, it hangs without giving any meaningful error messages.

I'm running this on a Raspberry Pi 3. The OS is Raspbian Stretch Lite.

Here is is the lighttpd log output.

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

You can see where I press CTRL C to kill the process. As you can see, I cannot find any meaningful error messages in this log. This log is displaying the first line 2018-01-04 19:56:16: (log.c.217) server started, then I go to the url in my browser (which is the local IP of the server). However, nothing happens in my browser, until I kill the process. Then I receive a 500 internal server error message (in the browser).

Here is my fastcgi script.

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

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

And here is my lighttpd.conf file.

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"
         ))
         )
    }
}

In my lighttpd script I'm using the python3 interpreter inside of my virtualenv directory, which has all the dependencies required for my flask app.

Please give me any help or advice you think is necessary in trying to get this to work, thank you.

Update

I discovered that sometimes, lighttpd does give me a traceback, but it's not a complete traceback. Here's what I got.

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>
Michael
  • 153
  • 1
  • 7
  • Questions regarding Rasberry Pi and Raspbian are [off-topic](https://meta.serverfault.com/questions/5586/are-raspberrypis-ever-on-topic-for-serverfault) here at Server Fault. Your question may be better suited at [Raspberry Pi](https://raspberrypi.stackexchange.com/) or [Super User](https://superuser.com/). – Paul Jan 06 '18 at 17:31
  • Okay, I reposted this question here. https://raspberrypi.stackexchange.com/questions/77556/lighttpd-running-fastcgi-script-hangs-and-give-500-internal-error – Michael Jan 10 '18 at 21:45

0 Answers0