You are not logged in.

#1 2014-08-04 19:58:57

Varda Elbereth
Member
Registered: 2014-08-04
Posts: 2

Web.py + FastCGI + Lighttpd?

So, I'm trying to make an extremely simple page that simply says "Hello World!" with fastcgi, web.py, etc. as I'm trying desperately to migrate from openshift to linode due to speed constraints, etc.

I have a working python application, but currently I can't even get simple pages to run. So given this example...



/etc/lighttpd/lighttpd.conf

include "conf.d/cgi.conf"
include "conf.d/fastcgi.conf"

server.port             = 80
server.username         = "http"
server.groupname        = "http"
server.document-root    = "/srv/http"
server.errorlog         = "/var/log/lighttpd/error.log"
dir-listing.activate    = "enable"
#index-file.names       = ( "index.html" )
mimetype.assign         = (
                                ".html" => "text/html",
                                ".txt" => "text/plain",
                                ".css" => "text/css",
                                ".js" => "application/x-javascript",
                                ".jpg" => "image/jpeg",
                                ".jpeg" => "image/jpeg",
                                ".gif" => "image/gif",
                                ".png" => "image/png",
                                "" => "application/octet-stream"
                        )

/etc/lighttpd/conf.d/cgi.conf

server.modules += ( "mod_cgi" )

cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                               ".cgi" => "/usr/bin/perl",
                               ".rb"  => "/usr/bin/ruby",
                               ".erb" => "/usr/bin/eruby",
                               ".py"  => "/usr/bin/python",
                               ".php" => "/usr/bin/php-cgi" )

index-file.names           += ( "index.pl",   "default.pl",
                               "index.rb",   "default.rb",
                               "index.erb",  "default.erb",
                               "index.py",   "default.py",
                               "index.php",  "default.php" )

/etc/lighttpd/conf.d/fastcgi.conf

server.modules += ( "mod_fastcgi" )

fastcgi.server = (
    ".py" =>
    (
        "python-fcgi" =>
        (
        "socket" => "/run/lighttpd/fastcgi.python.socket",
         "bin-path" => "test.py",
         "check-local" => "disable",
         "max-procs" => 1,
        )
    )
)

/srv/http/test.py

import web

urls = ("/.*", "hello")
app = web.application(urls, globals())

class hello:
    def GET(self):
        return 'Hello, world!'

if __name__ == "__main__":
    app.run()

Why am I currently getting an error starting lighttpd saying:

2014-08-04 15:53:47: (log.c.164) server started
2014-08-04 15:53:47: (mod_fastcgi.c.1112) the fastcgi-backend test.py failed to start:
2014-08-04 15:53:47: (mod_fastcgi.c.1116) child exited with status 2 test.py
2014-08-04 15:53:47: (mod_fastcgi.c.1119) If you're trying to run your app as a FastCGI backend, make sure you're using the FastCGI-enabled version.
If this is PHP on Gentoo, add 'fastcgi' to the USE flags.
2014-08-04 15:53:47: (mod_fastcgi.c.1406) [ERROR]: spawning fcgi failed.
2014-08-04 15:53:47: (server.c.1022) Configuration of plugins failed. Going down

Offline

#2 2014-08-04 22:25:00

Varda Elbereth
Member
Registered: 2014-08-04
Posts: 2

Re: Web.py + FastCGI + Lighttpd?

Okay, so for what it's worth I have a working Hello World now. I don't really get what I was doing wrong, but here are the config files of the working version.

I haven't found many simple lighttpd+web.py+fastcgi examples out there, so hopefully this is useful for someone... This is for Arch on linode.

/etc/lighttpd/lighttpd.conf

#include "conf.d/cgi.conf"
include "conf.d/fastcgi.conf"

server.modules              = (
            "mod_access",
            "mod_fastcgi",
            "mod_alias",
            "mod_rewrite",
            "mod_accesslog",
            "mod_compress",
)

server.port             = 80
server.username         = "http"
server.groupname        = "http"
server.document-root    = "/srv/http"
server.errorlog         = "/var/log/lighttpd/error.log"
dir-listing.activate    = "enable"
#index-file.names       = ( "index.html" )
mimetype.assign         = (
                                ".html" => "text/html",
                                ".txt" => "text/plain",
                                ".css" => "text/css",
                                ".js" => "application/x-javascript",
                                ".jpg" => "image/jpeg",
                                ".jpeg" => "image/jpeg",
                                ".gif" => "image/gif",
                                ".png" => "image/png",
                                "" => "application/octet-stream"
                        )

/etc/lighttpd/conf.d/fastcgi.conf

fastcgi.server = ( "/" =>
    ((
   "socket" => "/tmp/fastcgi.socket",
   "bin-path" => "/srv/http/index.py",
   "max-procs" => 1,
   "bin-environment" => (
     "REAL_SCRIPT_NAME" => ""
   ),
   "check-local" => "disable"
    ))
)

index.py:

#!/usr/bin/python2.7

import web

urls = ("/", "hello",
        "/pies", "hello2")
app = web.application(urls, globals())

class hello:
    def GET(self):
        return 'Hello, world!'

class hello2:
    def GET(self):
        return 'Hello, world AGAIN!'

if __name__ == "__main__":
    app.run()

/etc/lighttpd/conf.d/cgi.conf (though this shouldn't matter as it is commented out, presented for completion as plain CGI works as well...)

server.modules += ( "mod_cgi" )

cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                               ".cgi" => "/usr/bin/perl",
                               ".rb"  => "/usr/bin/ruby",
                               ".erb" => "/usr/bin/eruby",
                               ".py"  => "/usr/bin/python",
                               ".php" => "/usr/bin/php-cgi" )

index-file.names           += ( "index.pl",   "default.pl",
                               "index.rb",   "default.rb",
                               "index.erb",  "default.erb",
                               "index.py",   "default.py",
                               "index.php",  "default.php" )

Offline

Board footer

Powered by FluxBB