【问题标题】:lighttpd + mod_fastcgi + djangolighttpd + mod_fastcgi + django
【发布时间】:2012-10-21 09:38:08
【问题描述】:

我无法将我的 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/)

【问题讨论】:

    标签: django fastcgi lighttpd mod-fastcgi


    【解决方案1】:

    您似乎缺少文档中给出的重写指令:

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

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

    【讨论】:

    • 谢谢。我添加了它,现在我有一个 404 错误,大概是因为 nonorientable.fcgi 实际上并不存在。另外,我应该放 /var/www/myurl/nonorientable.fcgi 还是只放 /myurl/nonorientable.fcgi?
    • 尝试删除myurl,在fastcgi.server 部分使用/mysite.fcgi 并重写。正如文档中所说,fcgi 文件不必存在。
    • 有效!我现在遇到了静态文件的问题,但那是另一回事了……谢谢!
    • 很高兴听到您已经成功了!上面的url.rewrite-once 部分将提供来自/var/www/myurl/media/ 的媒体文件。希望您可以为静态文件添加类似的条目。
    猜你喜欢
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 2012-08-13
    • 2011-01-17
    • 1970-01-01
    • 2012-11-16
    • 2013-03-20
    相关资源
    最近更新 更多