我在/foo
上下文的Tomcat中运行了一个WAR应用程序,这意味着它的URL是http://example.com:8080/foo
。现在我正在尝试通过mod_jk将Apache HTTP Server连接到Tomcat。这是我的workers.properties
文件:
worker.list=foo
worker.foo.port=8009
worker.foo.host=localhost
worker.foo.type=ajp13
worker.foo.mount=/foo/*
工作正常,但在此网址:http://example.com/foo
。我希望它在http://example.com
。我错过了什么?
PS。这是我的mod-jk.conf
,它包含在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>
答案 0 :(得分:9)
您基本上有两个选择:
对于第二个选项,您的Apache配置看起来像这样:
# 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的目录可能就是答案)。
如果你需要了解更多关于mod_rewrite(非常强大的野兽)的信息,请点击此处: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule
答案 1 :(得分:0)
这是一个Mod Rewrite Solution
<强> WORKERS.PROPERTIES 强>
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.mount=/foo/* #THIS IS THE APP NAME: "FOO"
<强> HTTPD.CONF 强>
<VirtualHost *:80>
RewriteEngine On
RewriteRule ^/(.*)/Foo/$1 [PT]
ServerName example.com #DOMAIN NAME: "example.com"
ServerAlias www.example.com
JkMount /foo/* worker1
</VirtualHost>