如何使用 mod_jk 挂载上下文引用的 Tomcat 应用程序? [英] How to mount context-referenced Tomcat application with mod_jk?

查看:40
本文介绍了如何使用 mod_jk 挂载上下文引用的 Tomcat 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WAR 应用程序在 /foo 上下文中运行在 Tomcat 中,这意味着它的 URL 是 http://example.com:8080/foo.现在我正在尝试通过 mod_jk 将 Apache HTTP Server 连接到 Tomcat.这是我的 workers.properties 文件:

I have an WAR application running in Tomcat at /foo context, meaning that its URL is http://example.com:8080/foo. Now I'm trying to connect Apache HTTP Server to Tomcat through mod_jk. This is my workers.properties file:

worker.list=foo
worker.foo.port=8009
worker.foo.host=localhost
worker.foo.type=ajp13
worker.foo.mount=/foo/*

工作正常,但在此 URL:http://example.com/foo.我希望它位于 http://example.com.我错过了什么?

Works fine, but at this URL: http://example.com/foo. I would like it to be at http://example.com. What am I missing?

ps.这是我的 mod-jk.conf,它包含在 httpd.conf 中:

ps. This is my mod-jk.conf, which is included into httpd.conf:

LoadModule jk_module modules/mod_jk.so
JkWorkersFile /usr/local/tomcat/conf/workers.properties
<VirtualHost *:80>
  ServerName foo.example.com
  JkMount /* foo
</VirtualHost>

推荐答案

你基本上有两个选择:

  1. 修改您的 Tomcat 配置以将 WAR 挂载到根目录.这是如何完成的取决于您部署应用程序的确切方式.除非有一些预防因素,否则这是更简洁的方法.
  2. 解决Apache端的问题,使用mod_rewrite将/开头的URL重写为/foo,此时它将通过你的JkMount传递给Tomcat

对于第二个选项,您的 Apache 配置将如下所示:

For the second option, your Apache configuration would look something like this:

# Turn on mod_rewrite
RewriteEngine On
# This is the rule. Use regexp to match any URL beginning with /, and rewrite it to
# /foo/remaining_part_of_URL. The [PT] (pass-through) is necessary to make rewritten
# requests go through JkMount
RewriteRule ^/(.*) /foo/$1 [PT]

# Forward all URLs starting with foo to Tomcat
JkMount /foo/* worker

(这实际上没有经过测试,希望它按原样工作!).您可能还需要在 Apache 中启用 mod_rewrite(查看您的发行版,启用 mods 的目录可能就是答案).

(this isn't actually tested, hope it works as is!). You may also need to enable mod_rewrite in your Apache (check out your distribution, a mods-enabled directory might be the answer).

如果您需要了解更多有关 mod_rewrite(相当强大的野兽)的信息,请访问此处:http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule

And if you need to know more about mod_rewrite (quite a powerful beast), go here: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule

这篇关于如何使用 mod_jk 挂载上下文引用的 Tomcat 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆