lighttpd + mod_fastcgi + django

时间:2012-10-31 19:36:17

标签: django fastcgi lighttpd mod-fastcgi

我无法将django应用程序部署到使用lighttpd的服务器上(我是root用户)。

这是我的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"))

然后我在我的服务器上运行(从文件夹/var/www/myurl): sudo python manage.py runfcgi daemonize=false socket=/tmp/myurl.sock maxrequests=1

此时,当我尝试加载myurl.com时,我得到的只是目录列表:我的django应用程序未执行。我认为问题是mod_fastcgi在我的conf中被评论,它实际上出现在myurl.com/server-config上。如果我取消注释,lighttpd会抱怨我正在尝试加载相同的模块两次并退出,所以我的猜测是默认导入它。

我在ubuntu 12.04上使用django1.4(最新稳定版)和lighttpd 1.4.28版,我很困惑。我按照官方文件(https://docs.djangoproject.com/en/1.4/howto/deployment/fastcgi/)

1 个答案:

答案 0 :(得分:2)

看起来你错过了docs中给出的重写指令:

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

更新:您需要将fastcgi.server部分从/myurl/nonorientable.fcgi更改为/mysite.fcgi,以便与上面的重写相匹配。