How to mount a Tomcat application with context link with mod_jk?

I have a WAR application running in Tomcat in context /foo, which means its URL http://example.com:8080/foo. Now I am trying to connect Apache HTTP Server to Tomcat via mod_jk . This is my workers.propertiesfile:

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

It works fine, but on the URL-address: http://example.com/foo. I wish he was in http://example.com. What am I missing?

ps. This is mine mod-jk.conf, which is included in 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>
+3
source share
2 answers

Basically you have two options:

  • Tomcat, WAR . , , . , - .
  • Apache mod_rewrite, URL-, /to/foo, JkMount Tomcat

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

( , , !). , mod_rewrite Apache ( , , ).

mod_rewrite ( ), : http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule

+9

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>
0

Source: https://habr.com/ru/post/1795156/


All Articles