如果静态文件不存在,请配置Lighttpd以调用FastCGI应用程序

时间:2014-06-12 13:04:22

标签: fastcgi lighttpd

如果指定路径上不存在静态文件,如何配置Lighttpd来调用FastCGI应用程序? Lighttpd中的FastCGI模块支持配置选项“check-local”。如果设置为“enable”,Lighttpd将检查所请求的文件是否存在于文档根目录中。它将返回文件(如果存在)或响应404错误。但是,如果文件不存在,FastCGI应用程序将不会执行。

我想实现以下场景:

  • 用户请求/images/example.jpg
  • 图片存在=>返回图片
  • 图片不存在=>使用FastCGI应用程序生成图像

我在Lighttpd中使用以下配置:

server.modules += ( "mod_fastcgi" )
$HTTP["host"] == "localhost" {
    fastcgi.server += ( "/" =>
        ((
            "bin-path" => "/path/to/fcgi/app",
            "socket" => "/var/run/lighttpd/foobar.socket",
            "max-procs" => 8,
            "check-local" => "disable"
        ))
    )
}

修改 我刚刚找到了解决方法。也许有更好的解决方案?

server.modules += ( "mod_fastcgi" )
server.modules += ( "mod_rewrite" )
$HTTP["host"] == "localhost" {
    url.rewrite-if-not-file = (
        "^(.*)$" => "$1?create=true"
    )
    $HTTP["querystring"] =~ "create=true" {
        fastcgi.server += ( "/" =>
            ((
                "bin-path" => "/path/to/fcgi/app",
                "socket" => "/var/run/lighttpd/foobar.socket",
                "max-procs" => 8,
                "check-local" => "disable"
            ))
        )
    }
}

0 个答案:

没有答案
相关问题