简体   繁体   English

Apache mod_perl处理程序/调度程序将控制权返回给apache

[英]Apache mod_perl handler/dispatcher returning control to apache

Is it possible to have an apache mod_perl handler, which receives all incoming requests and decides based upon a set of rules if this request is something it wants to act upon, and if not, return control to apache which would serve the request as normal? 是否有可能使用apache mod_perl处理程序,该处理程序接收所有传入的请求并根据一组规则来决定是否要对其执行此请求,如果不是,则将控制权返回给将正常处理该请求的apache?

A use-case: 用例:

A legacy site which uses DirectoryIndex for serving index.html (or similar) and default handlers for perl scripts etc, is being given a freshened up url-scheme (django/catalyst-ish). 使用DirectoryIndex提供index.html(或类似内容)和Perl脚本等默认处理程序的旧站点,将获得更新的url模式(django / catalyst-ish)。 A dispatcher will have a set of urls mapped to controllers that are dispatched based on the incoming url. 调度程序将具有一组URL,这些URL映射到根据传入URL进行调度的控制器。

However, the tricky part is having this dispatcher within the same namespace on the same vhost as the old site. 但是,棘手的部分是在与旧站点相同的虚拟主机上的同一名称空间中拥有此调度程序。 The thought is to rewrite the site piece by piece, as a "update all" migration gives no chance in testing site performance with the new system, nor is it feasible due to the sheer size of the site. 这样做的想法是逐个重写站点,因为“全部更新”迁移不会给新系统测试站点性能带来任何机会,而且由于站点规模巨大,这也不可行。

One of the many problems, is that the dispatcher now receives all URLs as expected, but DirectoryIndex and static content (which is mostly served by a different host, but not everything) is not served properly. 许多问题之一是,调度程序现在可以按预期接收所有URL,但是DirectoryIndex和静态内容( 主要由不同的主机提供服务,但不是所有服务)都不能正确提供。 The dispatcher returns an Apache::Const::DECLINED for non-matching urls, but Apache does not continue to serve the request as it normally would, but instead gives the default error page. 调度程序为不匹配的URL返回一个Apache :: Const :: DECLINED,但是Apache不会像往常一样继续为请求提供服务,而是提供了默认错误页面。 Apache does not seem to try to look for /index.html etc. Apache似乎没有尝试寻找/index.html等。

How can this be solved? 如何解决呢? Do you need to use internal redirects? 您是否需要使用内部重定向? Change the handler stack in the dispatcher? 更改调度程序中的处理程序堆栈? Use some clever directives? 使用一些聪明的指令? All of the above? 上述所有的? Not possible at all? 根本不可能吗?

All suggestions are welcome! 欢迎提出所有建议!

I have done a similar thing but a while back, so I might be a little vague: 我做了类似的事情,但不久前,所以我可能有点含糊:

  • I think you need to have the standard file handler (I believe this is done using the set-handler directive) as well as the perl handler in the stack 我认为您需要具有标准文件处理程序(我相信这是使用set-handler指令完成的)以及堆栈中的perl处理程序
  • You might need to use PerlTransHandler or a similar one to hook into the filename/url mapping phase and make sure the next handler inline will pick the right file up off the filesystem. 您可能需要使用PerlTransHandler或类似的工具来挂接到文件名/ URL映射阶段,并确保下一个内联处理程序将从文件系统中提取正确的文件。

Maybe you will have success using a mod_rewrite configuration which only does rewrite URLs to your dispatcher if a requested file does not exist in the file system. 使用mod_rewrite配置也许会成功,该配置仅在文件系统中不存在请求的文件时才将URL重写到调度程序。 That way your new application acts as an overlay to the old application and can be replaced in successive steps by just removing old parts of the application during deployment of new parts. 这样,您的新应用程序将充当旧应用程序的覆盖,并且可以在后续步骤中通过在部署新部件的过程中仅移除应用程序的旧部件来进行替换。

This can be accomblished by a combination of RewriteCond and RewriteRule. 这可以通过结合RewriteCond和RewriteRule来完成。 Your new application needs to sit in a private "namespace" (location) not otherwise used in the old application. 您的新应用程序需要位于一个专用的“名称空间”(位置)中,而旧应用程序中没有使用该名称空间。

I am not a mod_perl expert but with eg mod_php it could work like this: 我不是mod_perl专家,但是使用mod_php可以这样工作:

RewriteEngine on

# do not rewrite requests into the new application(s) / namespaces
RewriteRule ^new_app/ - [L]

# do not rewrite requests to existing file system objects
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

# do the actual rewrite here
RewriteRule ^(.*)$ new_app/dispatcher.php/$1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM