我有一个在/foo上下文中在Tomcat中运行的WAR应用程序,这意味着它的URL是http://example.com:8080/foo。现在,我正在尝试通过mod_jk将Apache HTTP Server连接到Tomcat 。这是我的workers.properties文件:
/foo
http://example.com:8080/foo
workers.properties
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。我想念什么?
http://example.com/foo
http://example.com
ps。这是我的mod-jk.conf,包含在httpd.conf:
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>
您基本上有两个选择:
对于第二个选项,您的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