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

发布于 2024-08-20 17:43:56 字数 739 浏览 10 评论 0原文

是否可以有一个 apache mod_perl 处理程序,它接收所有传入请求并根据一组规则决定该请求是否是它想要执行的操作,如果不是,则将控制权返回给 apache,apache 将正常处理该请求?

用例:

旧网站使用 用于服务index.html的DirectoryIndex (或类似)和默认处理程序 perl 脚本等,正在被给予 更新了 url-scheme (django/catalyst-ish)。调度员 将有一组映射到的 url 基于调度的控制器 在传入的 URL 上。

然而,棘手的部分是 该调度程序在同一 命名空间与旧主机位于同一虚拟主机上 地点。想法是重写 逐个站点,作为“全部更新” 迁移没有机会进行测试 新系统的站点性能, 由于纯粹的原因,这也是不可行的 网站的大小。

许多问题之一是调度程序现在按预期接收所有 URL,但 DirectoryIndex 和静态内容(主要由不同主机提供,但不是所有内容)未正确提供。对于不匹配的 url,调度程序返回 Apache::Const::DECLINED,但 Apache 不会像平常那样继续处理请求,而是提供默认的错误页面。 Apache似乎没有尝试寻找/index.html等。

如何解决这个问题?您需要使用内部重定向吗?更改调度程序中的处理程序堆栈?使用一些巧妙的指令?上述所有的?根本不可能吗?

欢迎所有建议!

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?

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). A dispatcher
will have a set of urls mapped to
controllers that are dispatched based
on the incoming 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. 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. Apache does not seem to try to look for /index.html etc.

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无可置疑 2024-08-27 17:43:56

我不久前做过类似的事情,所以我可能有点含糊:

  • 我认为你需要有标准的文件处理程序(我相信这是使用 set-handler 指令完成的)以及 perl 处理程序堆栈
  • 您可能需要使用 PerlTransHandler 或类似的一个挂钩到文件名/url 映射阶段,并确保下一个内联处理程序将从文件系统中选取正确的文件。

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
  • 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.
长途伴 2024-08-27 17:43:56

也许您会成功使用 mod_rewrite 配置,该配置仅在文件系统中不存在所请求的文件时才将 URL 重写到您的调度程序。这样,您的新应用程序将充当旧应用程序的覆盖,并且可以通过在部署新部分期间删除应用程序的旧部分来按连续步骤进行替换。

这可以通过 RewriteCond 和 RewriteRule 的组合来实现。您的新应用程序需要位于旧应用程序中不使用的私有“命名空间”(位置)中。

我不是 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

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. 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. 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:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文