找不到静态文件 - 带有fastcgi fcgi的Lighttpd

时间:2014-04-27 22:49:00

标签: python lighttpd fastcgi

我的python文件很有趣,fcgi没有问题,但我的静态内容产生404错误。

我的fastcgi.conf:

server.modules += ( "mod_fastcgi" )
fastcgi.server = ("/" =>
    ((  
        "socket" => "/tmp/webxyz-fcgi.sock",
        "bin-path" => "/opt/local/www/xyz/webxyz.fcgi",
        "check-local" => "disable",
        "max-procs" => 1
    ))  
)

alias.url = ( 
    "/static" => "/opt/local/www/xyz/app/static"
)

url.rewrite-once = ( 
    #"^(/static($|/.*))$" => "$1",
    "^(/static.*)$" => "$1",
    "^(/.*)$" => "/webxyz.fcgi$1"
)

我打开了一些调试:

debug.log-request-handling        = "enable"
debug.log-request-header-on-error = "enable"
debug.log-file-not-found          = "enable"

(虽然奇怪的文件找不到似乎没有做任何事......)

这里是我在error.log中看到的一个静态文件 - 所有其他的产生类似的输出(下面的省略号是一堆只有行号变化的无信息条件块):

2014-04-27 15:20:24: (response.c.340) Request-URI     :  /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js 
2014-04-27 15:20:24: (response.c.341) URI-scheme      :  http 
2014-04-27 15:20:24: (response.c.342) URI-authority   :  75.101.102.25:8080 
2014-04-27 15:20:24: (response.c.343) URI-path (raw)  :  /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js 
2014-04-27 15:20:24: (response.c.344) URI-path (clean):  /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js 
2014-04-27 15:20:24: (response.c.345) URI-query       :   
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false 
2014-04-27 15:20:24: (response.c.249) run condition 
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.273) 2 global/HTTPurl=~\.pdf$ nej 
2014-04-27 15:20:24: (configfile-glue.c.530) 1 (uncached) result: unknown 
...
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.467) HTTP["url"] ( /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js ) compare to  \.pdf$ 
2014-04-27 15:20:24: (configfile-glue.c.530) 1 (uncached) result: false 
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false 
2014-04-27 15:20:24: (response.c.339) -- splitting Request-URI 
2014-04-27 15:20:24: (response.c.340) Request-URI     :  /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js 
2014-04-27 15:20:24: (response.c.341) URI-scheme      :  http 
2014-04-27 15:20:24: (response.c.342) URI-authority   :  75.101.102.25:8080 
2014-04-27 15:20:24: (response.c.343) URI-path (raw)  :  /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js 
2014-04-27 15:20:24: (response.c.344) URI-path (clean):  /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js 
2014-04-27 15:20:24: (response.c.345) URI-query       :   
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false 
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false 
2014-04-27 15:20:24: (mod_access.c.135) -- mod_access_uri_handler called 
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false 
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false 
2014-04-27 15:20:24: (mod_fastcgi.c.3626) handling it in mod_fastcgi 
2014-04-27 15:20:24: (response.c.473) -- before doc_root 
2014-04-27 15:20:24: (response.c.474) Doc-Root     : /opt/local/www/htdocs 
2014-04-27 15:20:24: (response.c.475) Rel-Path     : /static 
2014-04-27 15:20:24: (response.c.476) Path         :  
2014-04-27 15:20:24: (response.c.524) -- after doc_root 
2014-04-27 15:20:24: (response.c.525) Doc-Root     : /opt/local/www/htdocs 
2014-04-27 15:20:24: (response.c.526) Rel-Path     : /static 
2014-04-27 15:20:24: (response.c.527) Path         : /opt/local/www/htdocs/static 
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false 
2014-04-27 15:20:24: (response.c.544) -- logical -> physical 
2014-04-27 15:20:24: (response.c.545) Doc-Root     : /opt/local/www/htdocs 
2014-04-27 15:20:24: (response.c.546) Basedir      : /opt/local/www/xyz/app/static 
2014-04-27 15:20:24: (response.c.547) Rel-Path     : /static 
2014-04-27 15:20:24: (response.c.548) Path         : /opt/local/www/xyz/app/static 
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false 
2014-04-27 15:20:24: (response.c.249) run condition 
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block === 
2014-04-27 15:20:24: (configfile-glue.c.273) 2 global/HTTPurl=~\.pdf$ nej 
...

它查看的最后一条路径,/ opt / local / www / xyz / app / static是我的静态目录,包含bower_components / x-editable / dist / bootstrap3-editable / js / bootstrap-editable .js

我不确定为什么没找到它 - 权限很好:

sudo -u www cat /opt/local/www/xyz/app/static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js

按预期工作。

任何指导或建议表示赞赏。

1 个答案:

答案 0 :(得分:1)

确定。

所以阅读this帖子,我看到我使用werkzeug.contrib.fixers.CGIRootFix让我将我的fcgi的范围定义为“/”,它优先于url和重写规则为“/ static”。将fcgi服务器包装在一个条件中以排除以“/ static”开头的url请求,解决了没有提供静态内容的问题。

这是工作fastcgi.conf:

server.modules += ( "mod_fastcgi" )
$HTTP["url"] !~ "^/static" {
    fastcgi.server = ("/" =>
        ((  
            "socket" => "/tmp/webpdb-fcgi.sock",
            "bin-path" => "/opt/local/www/xyz/webxyz.fcgi",
            "check-local" => "disable",
            "max-procs" => 1
        ))  
    )   
}

alias.url = ( 
    "/static" => "/opt/local/www/xyz/app/static"
)

url.rewrite-once = ( 
    #"^(/static($|/.*))$" => "$1",
    "^(/static.*)$" => "$1",
    "^(/.*)$" => "/webxyz.fcgi$1"
)