lighttpd fastcgi:如何恢复剥离的URL路径元素?

时间:2016-10-22 10:38:24

标签: url-rewriting fastcgi lighttpd

我正在实现一个(相当复杂的)RESTful API。

我使用Lighttpd作为带有两个 FastCGI后端的Web服务器:

  • 大量请求的通用PHP处理程序
  • 用于其他几个请求的专用C ++处理程序

我当前的fastcgi.conf看起来像(简化):

server.modules += ( "mod_fastcgi" )

fastcgi.server = ( ".php" => ( "PHP" => (
                 "bin-path" => "/usr/bin/php-cgi",
                 "socket" => "/tmp/php.socket",
                 "check-local" => "disable",
                 "bin-environment" => ( "PHP_FCGI_CHILDREN" => "0", "PHP_FCGI_MAX_REQUESTS" => "500" ),
                 "bin-copy-environment" => ( "PATH", "SHELL", "USER" ),
                 "max-procs" => 1,
                 "broken-scriptfilename" => "enable"
             )),
               "/api/groupA" => ( "Server" => (
                 "socket" => "/tmp/fcgi-C.socket",
                 "check-local" => "disable",
             )),
               "/api/groupB" => ( "Server" => (
                 "socket" => "/tmp/fcgi-C.socket",
                 "check-local" => "disable",
             )),
               "/api/groupC" => ( "Server" => (
                 "socket" => "/tmp/fcgi-C.socket",
                 "check-local" => "disable",
             )),
               "/api/" => ( "PHP" => (
                 "bin-path" => "/usr/bin/php-cgi",
                 "socket" => "/tmp/php-P.socket",
                 "check-local" => "disable",
                 "bin-environment" => ( "PHP_FCGI_CHILDREN" => "0", "PHP_FCGI_MAX_REQUESTS" => "500" ),
                 "bin-copy-environment" => ( "PATH", "SHELL", "USER" ),
                 "max-procs" => 1,
                 "broken-scriptfilename" => "enable"
             ))
             )

这意味着我过滤了用于C ++处理的前缀,并将其余部分默认为PHP。

PHP部分按预期工作。

这里的问题是C ++处理程序收到一个截断的请求路径,其中“/ group(A | B | C)”被剥离(每个人都获得没有前导“/ api”的路径,但那没关系。)

如何恢复完整路径?

或者:是否(或者我可以制作)某些变量/标题/我可以在C ++中测试什么来获得“缺少的部分”?

我已经做好充分的准备来处理冗余信息(例如:路径恢复到完整的“/ api / ...”),但我需要丢弃的信息。

唯一想到的就是区分套接字并使用过滤器根据实际的传入套接字恢复信息,但这似乎过于复杂且非常脆弱;我希望有一个更简单的解决方案,可能涉及URL重写(我熟悉Lighttpd配置错综复杂,我更像是一个C ++ / PHP / java编码器,所以我希望我忽略了明显的东西;))

1 个答案:

答案 0 :(得分:0)

客户的原始请求可以在REQUEST_URI中找到。

mod_fastcgi还有配置选项,允许对损坏的PHP进行有限的URL修改。 https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI