找不到静态文件 - Lighttpd 配置 FastCGI

1 投票
1 回答
700 浏览
提问于 2025-04-18 04:31

我的 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 个回答

2

好的。

我在阅读这篇帖子时发现,我使用的werkzeug.contrib.fixers.CGIRootFix导致我把fcgi的范围定义为“/”,这就覆盖了“/static”的网址和重写规则。为了修复没有静态内容被提供的问题,我把fcgi服务器放在一个条件里,排除了以“/static”开头的网址请求。

下面是可以正常工作的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"
)

撰写回答