lighttpd fastcgi:如何恢复剥离的 URL 路径元素?
lighttpd fastcgi: how to restore stripped URL path elements?
我正在实施一个(相当复杂的)RESTful API。
我使用 Lighttpd 作为网络服务器,两个 FastCGI 后端:
- 用于大量请求的通用 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”的路径,但没关系) .
如何恢复完整路径?
或者:是否有(或者我可以生成)一些 variable/header/whatever 我可以在 C++ 中测试以获得 "missing part"?
我已经做好了应对冗余信息的充分准备(例如:路径恢复为完整的“/api/...”),但我需要被丢弃的信息
唯一想到的是区分套接字并使用过滤器根据实际传入的套接字恢复信息,但这似乎过于复杂且非常脆弱;我希望有一个更简单的解决方案,可能涉及 URL-重写(我 不 熟悉错综复杂的 Lighttpd 配置,我更像是 C++/PHP/java 编码器,所以我希望我忽略了一些明显的东西 ;) )
客户端的原始请求可以在REQUEST_URI中找到。
mod_fastcgi 也有配置选项,允许对损坏的 PHP 进行有限的 URL 重整。
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI
我正在实施一个(相当复杂的)RESTful API。
我使用 Lighttpd 作为网络服务器,两个 FastCGI 后端:
- 用于大量请求的通用 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”的路径,但没关系) .
如何恢复完整路径?
或者:是否有(或者我可以生成)一些 variable/header/whatever 我可以在 C++ 中测试以获得 "missing part"?
我已经做好了应对冗余信息的充分准备(例如:路径恢复为完整的“/api/...”),但我需要被丢弃的信息
唯一想到的是区分套接字并使用过滤器根据实际传入的套接字恢复信息,但这似乎过于复杂且非常脆弱;我希望有一个更简单的解决方案,可能涉及 URL-重写(我 不 熟悉错综复杂的 Lighttpd 配置,我更像是 C++/PHP/java 编码器,所以我希望我忽略了一些明显的东西 ;) )
客户端的原始请求可以在REQUEST_URI中找到。
mod_fastcgi 也有配置选项,允许对损坏的 PHP 进行有限的 URL 重整。 https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI