djangofastcgilighttpdmod-fastcgi

lighttpd + mod_fastcgi + django


I am having trouble deploying my django app to a server that uses lighttpd (on which I'm root.)

Here's my lighttpd.conf:

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

status.status-url          = "/server-status"
status.config-url          = "/server-config"

$HTTP["host"] == "myurl.com" {
server.document-root = "/var/www/myurl"
server.errorlog = "/var/log/lighttpd/myurl/error.log"
accesslog.filename = "var/log/lighttpd/nixcraft/access.log"
server.error-handler-404 = "/e404.html"

fastcgi.server = (
    "/myurl/nonorientable.fcgi" => (
        "main" => (
            # Use host / port instead of socket for TCP fastcgi                                                                                                                      
            # "host" => "127.0.0.1",                                                                                                                                                 
            # "port" => 3033,                                                                                                                                                        
            "socket" => "/tmp/myurl.sock",
            "check-local" => "disable",
        )
    ),
)
}

server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"

index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm")

url.access-deny             = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )


## Use ipv6 if available                                                                                                                                                             
#include_shell "/usr/share/lighttpd/use-ipv6.pl"                                                                                                                                     

dir-listing.encoding        = "utf-8"
server.dir-listing          = "enable"

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/x-javascript", "text/css", "text/html", "text/plain" )

include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

server.modules += ( "mod_auth" )
auth.debug = 2
auth.backend = "plain"
auth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpassword"

auth.require = ( "/" =>
("method" => "basic",
 "realm" => "",
 "require" => "user=john"))

And then I ran this on my server (from the folder /var/www/myurl): sudo python manage.py runfcgi daemonize=false socket=/tmp/myurl.sock maxrequests=1

At this point, when I try to load myurl.com, all I get is the directory listing: my django app is not executed. I thought that the problem was that mod_fastcgi is commented in my conf, it actually appears on myurl.com/server-config. If I uncomment it, lighttpd complains that I'm trying to load the same module twice and exits, so my guess is that it is imported by default.

I'm using django1.4 (latest stable) and lighttpd 1.4.28 on ubuntu 12.04, and I'm pretty stuck. I followed the official doc (https://docs.djangoproject.com/en/1.4/howto/deployment/fastcgi/)


Solution

  • It looks like your missing the rewrite directive given in the docs:

    url.rewrite-once = (
        "^(/media.*)$" => "$1",
        "^/favicon\.ico$" => "/media/favicon.ico",
        "^(/.*)$" => "/mysite.fcgi$1",
    )
    

    Update: You need to change the fastcgi.server section from /myurl/nonorientable.fcgi to /mysite.fcgi so that it matches the rewrite above.