You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Shug Boabby <sh...@gmail.com> on 2007/11/04 05:32:18 UTC

jk_mod and binding tomcat's root to an apache directory

Hello everyone,

There does not appear to be a separate list for mod_jk discussions...  
so I assume this is the most relevant place to ask questions. Please  
let me know if there is somewhere more specific for me to bring this.

I have mod_jk up and running with Apache 2 and Tomcat 5.5. However, it  
seems that every single servlet must be mapped by hand in the apache  
config files! This seems like a lot of work to me. What I'd really  
like to do would be to map my server's "/tomcat" path to redirect any  
requests to Tomcat's root. e.g. a request coming in to my server at / 
tomcat/servlet-examples would be re-routed to Tomcat's /servlet-examples

Such a setup would mean zero admin in the Apache-Tomcat bridge when  
new servlets are added. As they are added to Tomcat, they immediately  
become accessible in Apache's /tomcat/ directory. Is it possible to  
set it up this way? It seems a very sensible way to do things.

Shug

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Shug Boabby <sh...@gmail.com>.
That's a bit of a bummer... I'm stumped, I don't know what could be  
going wrong.

It seems that the rewrite rule is working, the request is being sent  
to ajp and the only response is "No host matches server name  
mydomain.com".

Perhaps in the rewrite rules I need to specify that the request must  
go to 127.0.0.1? I have 2 ethernet cards... and by the look of the  
last log, perhaps the request is going out to my 2nd address and not  
the localhost! Any ideas on how to set that in the rewrite rule?

On 4 Nov 2007, at 18:37, Rainer Jung wrote:

> Yes, it will handle your config without problems. But you don't get
>
>    Apache: Add forwarding uri to debug log. (rjung)
>
> (from the changelog). :(
>
> Regards,
>
> Rainer
>
> Shug Boabby schrieb:
>> On 4 Nov 2007, at 18:26, Rainer Jung wrote:
>>> Then you are using an older version of JK. The up to date version is
>>> 1.2.25.
>>
>> By the looks of it, the latest Ubuntu Gutsy has 1.2.23... can it  
>> handle
>> this configuration?
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Rainer Jung <ra...@kippdata.de>.
Yes, it will handle your config without problems. But you don't get

    Apache: Add forwarding uri to debug log. (rjung)

(from the changelog). :(

Regards,

Rainer

Shug Boabby schrieb:
> On 4 Nov 2007, at 18:26, Rainer Jung wrote:
>> Then you are using an older version of JK. The up to date version is
>> 1.2.25.
> 
> By the looks of it, the latest Ubuntu Gutsy has 1.2.23... can it handle
> this configuration?

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Shug Boabby <sh...@gmail.com>.
On 4 Nov 2007, at 18:26, Rainer Jung wrote:
> Then you are using an older version of JK. The up to date version is  
> 1.2.25.

By the looks of it, the latest Ubuntu Gutsy has 1.2.23... can it  
handle this configuration?

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Rainer Jung <ra...@kippdata.de>.
Shug Boabby schrieb:
> I'm using pretty much the stock config for Tomcat... although I have
> added SSL support.
> 
> On 4 Nov 2007, at 17:14, Rainer Jung wrote:
>> There should be a line in the jk debug log similar to:
>>
>> [debug] init_ws_service::mod_jk.c (806): Service protocol=HTTP/1.1
>> method=GET host=(null) addr=127.0.0.1 name=localhost port=8001
>> auth=(null) user=(null) laddr=127.0.0.1 raddr=127.0.0.1
>> uri=/unrelated/page/on/my/site
>>
>> Check the uri, that's the one we send to Tomcat. Check the Tomcat logs,
>> if they show an error. Try to send the same request directly to Tomcat
>> via its http connector.
> 
> I see a line very similar to that one... but it is completely missing
> the 'uri' part. How come the uri would be missing?

Then you are using an older version of JK. The up to date version is 1.2.25.

> The rewrite rules are appearing in my debugging now... (this has been
> somewhat anonymised)
> 
> init rewrite engine with requested uri /tomcat/myapp/
> applying pattern '/tomcat/(.*)' to uri '/tomcat/myapp/'
> rewrite '/tomcat/myapp/' -> '/myapp/'
> setting env variable 'JK_WORKER_NAME' to 'worker1'
> remember /myapp/ to have Content-handler 'jakarta-servlet'
> forcing '/myapp/' to get passed through to next API URI-to-filename handler
> force filename /home/shug/public_html/myapp to have the Content-handler
> 'jakarta-servlet'

Looks good so far.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Shug Boabby <sh...@gmail.com>.
I'm using pretty much the stock config for Tomcat... although I have  
added SSL support.

On 4 Nov 2007, at 17:14, Rainer Jung wrote:
> There should be a line in the jk debug log similar to:
>
> [debug] init_ws_service::mod_jk.c (806): Service protocol=HTTP/1.1
> method=GET host=(null) addr=127.0.0.1 name=localhost port=8001
> auth=(null) user=(null) laddr=127.0.0.1 raddr=127.0.0.1
> uri=/unrelated/page/on/my/site
>
> Check the uri, that's the one we send to Tomcat. Check the Tomcat  
> logs,
> if they show an error. Try to send the same request directly to Tomcat
> via its http connector.

I see a line very similar to that one... but it is completely missing  
the 'uri' part. It looks pretty much like this

[debug] init_ws_service::mod_jk.c (607): Service protocol=HTTP/1.1  
method=GET host=(null) addr=public_ip name=mydomain.com port=8001  
auth=(null) user=(null) laddr=129.215.188.173 raddr=public_ip

where my public IP address appears in place of 'public_ip' and my  
virtual domain name (not the hostname of the server machine itself)  
appears instead of 'mydomain.com'. How come the uri would be missing?

The rewrite rules are appearing in my debugging now... (this has been  
somewhat anonymised)

init rewrite engine with requested uri /tomcat/myapp/
applying pattern '/tomcat/(.*)' to uri '/tomcat/myapp/'
rewrite '/tomcat/myapp/' -> '/myapp/'
setting env variable 'JK_WORKER_NAME' to 'worker1'
remember /myapp/ to have Content-handler 'jakarta-servlet'
forcing '/myapp/' to get passed through to next API URI-to-filename  
handler
force filename /home/shug/public_html/myapp to have the Content- 
handler 'jakarta-servlet'


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Rainer Jung <ra...@kippdata.de>.

Shug Boabby schrieb:
> Thanks Rainer... I've added the JK debugging and this has helped
> identify a problem... the response that Apache gets (and doesn't forward
> to the client) is that "No host matches server name myserver.com".

Tomcat gets the host name from the forwarded Host header. Are you using
vhosts in Tomcat, or are you using more or less the default config
(which I hope for the first step). In the default config, it should not
be a problem, that there is no Host named myserver.com defined in
server.xml.

There should be a line in the jk debug log similar to:

[debug] init_ws_service::mod_jk.c (806): Service protocol=HTTP/1.1
method=GET host=(null) addr=127.0.0.1 name=localhost port=8001
auth=(null) user=(null) laddr=127.0.0.1 raddr=127.0.0.1
uri=/unrelated/page/on/my/site

Check the uri, that's the one we send to Tomcat. Check the Tomcat logs,
if they show an error. Try to send the same request directly to Tomcat
via its http connector.

> I'm not seeing any output at all in the RewriteLog (btw, it's RewriteLog
> not RewriteLogFile). I'm using Apache 2.2.5.

Sorry. Concerning the empty log file: if you are using virtual hosts,
define the rewrite directives in the vhost. Especially the
"RewriteEngine On" should be in each vhost, that should use mod_rewrite.
Also the Rules are not automatically inherited, and by using individual
RewriteLog directives, you can define vhost private log files and thus
check, which vhost handled your request.

> Apache httpd is running several virtual domains, so this is a reasonable
> response. However, JkMount worked fine despite this so it's a little
> puzzling. I don't have a clue how to fix it! Any ideas?
> 
> Should I be concerned that the the JK log is completely full up of lines
> like this
> 
> "Attempting to map URI '/unrelated/page/on/my/site' from 2 maps"
> 
> every time I get an access request on my server... even though the pages
> have nothing to do with the JkMount points?

No, it's debug (non-production) and also shows us, how mod_jk tries to
decide, if it should forward the request. Those lines are the lines that
show, *if* any of the JkMounts match the URL.

> On 4 Nov 2007, at 15:41, Rainer Jung wrote:
>> Now we go into debugging mod_rewrite and mod_jk.
>>
>> RewriteLogFile logs/rewrite.log
>> RewriteLogLevel 9
>>
>> will give you information, what mod_rewrite does with your URL.
>>
>> JkLogFile logs/mod_jk.log
>> JkLogLevel debug
>>
>> will give us a lot of information, which URL gets passed to mod_jk, and
>> what it does with it.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Shug Boabby <sh...@gmail.com>.
Thanks Rainer... I've added the JK debugging and this has helped  
identify a problem... the response that Apache gets (and doesn't  
forward to the client) is that "No host matches server name  
myserver.com".

I'm not seeing any output at all in the RewriteLog (btw, it's  
RewriteLog not RewriteLogFile). I'm using Apache 2.2.5.

Apache httpd is running several virtual domains, so this is a  
reasonable response. However, JkMount worked fine despite this so it's  
a little puzzling. I don't have a clue how to fix it! Any ideas?

Should I be concerned that the the JK log is completely full up of  
lines like this

"Attempting to map URI '/unrelated/page/on/my/site' from 2 maps"

every time I get an access request on my server... even though the  
pages have nothing to do with the JkMount points?

On 4 Nov 2007, at 15:41, Rainer Jung wrote:
> Now we go into debugging mod_rewrite and mod_jk.
>
> RewriteLogFile logs/rewrite.log
> RewriteLogLevel 9
>
> will give you information, what mod_rewrite does with your URL.
>
> JkLogFile logs/mod_jk.log
> JkLogLevel debug
>
> will give us a lot of information, which URL gets passed to mod_jk,  
> and
> what it does with it.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Rainer Jung <ra...@kippdata.de>.
Shug Boabby schrieb:
> Thanks again Rainer,
> 
> I think we're getting somewhere with this... but unfortunately all
> responses to myserver.com/tomcat/anything are completely empty. This
> means something is happening because the response to myserver.com/tomcat
> is that it doesn't exist (because the rewrite rule doesn't apply if
> there is no trailing slash and it's trying to find the static page to
> serve).
> 
> I have noted the e-mail wrapping of the line and corrected for it.
> 
> My workers.properties file looks like
> 
> workers.tomcat_home=/usr/share/tomcat5.5
> workers.java_home=/usr/lib/jvm/java-6-sun
> ps=/

Delete the first three lines. They are non-functional and obsolete.

> worker.list=worker1
> worker.worker1.port=8009
> worker.worker1.host=localhost
> worker.worker1.type=ajp13
> worker.worker1.lbfactor=1

I don't understand the next line. It should not have any effect.

> /=worker1
> 
> and my apache configuration (after module loading etc) has
> 
> RewriteEngine On
> RewriteRule /tomcat/(.*) /$1
> [E=JK_WORKER_NAME:worker1,H=jakarta-servlet,PT]
> 
> I don't have any explicit JkMount lines anywhere and I'm not seeing
> anything unusual in my logs.

No JkMounts is OK, they are replaced by the RewriteRule. Are you using
Apache 2.2?

Now we go into debugging mod_rewrite and mod_jk.

RewriteLogFile logs/rewrite.log
RewriteLogLevel 9

will give you information, what mod_rewrite does with your URL.

JkLogFile logs/mod_jk.log
JkLogLevel debug

will give us a lot of information, which URL gets passed to mod_jk, and
what it does with it.

> Have any further ideas? I really appreciate your help on this.
> 
> On 4 Nov 2007, at 14:04, Rainer Jung wrote:
>> LoadModule rewrite_module modules/mod_rewrite.so
>> RewriteEngine On
>> RewriteRule /tomcat/(.*) /$1
>> [E=JK_WORKER_NAME:myworker,H=jakarta-servlet,PT]
>>
>> The RewriteRule line extends until "PT]"
>>
>> This will activate JK forwarding via a worker called myworker (you can
>> replace it by the name of your worker) for everything that starts with
>> /tomcat/ and also changes the forwarding URL by stripping the leading
>> "/tomcat".
>>
>> FOR Apache we use mod_rewrite for those tricks, because it is a modular
>> server and there exists many usefuk modules. For IIS this kind of
>> ability is already build into the JK isapi plugin.
>>
>> Is that what you are looking for?
>>
>> Note that now we don't replace /tomcat by /servlet-examples, so a
>> working request now would be /tomcat/servlet-example/something.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Shug Boabby <sh...@gmail.com>.
Thanks again Rainer,

I think we're getting somewhere with this... but unfortunately all  
responses to myserver.com/tomcat/anything are completely empty. This  
means something is happening because the response to myserver.com/ 
tomcat is that it doesn't exist (because the rewrite rule doesn't  
apply if there is no trailing slash and it's trying to find the static  
page to serve).

I have noted the e-mail wrapping of the line and corrected for it.

My workers.properties file looks like

workers.tomcat_home=/usr/share/tomcat5.5
workers.java_home=/usr/lib/jvm/java-6-sun
ps=/
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
/=worker1

and my apache configuration (after module loading etc) has

RewriteEngine On
RewriteRule /tomcat/(.*) /$1 [E=JK_WORKER_NAME:worker1,H=jakarta- 
servlet,PT]

I don't have any explicit JkMount lines anywhere and I'm not seeing  
anything unusual in my logs.

Have any further ideas? I really appreciate your help on this.

On 4 Nov 2007, at 14:04, Rainer Jung wrote:
> LoadModule rewrite_module modules/mod_rewrite.so
> RewriteEngine On
> RewriteRule /tomcat/(.*) /$1
> [E=JK_WORKER_NAME:myworker,H=jakarta-servlet,PT]
>
> The RewriteRule line extends until "PT]"
>
> This will activate JK forwarding via a worker called myworker (you can
> replace it by the name of your worker) for everything that starts with
> /tomcat/ and also changes the forwarding URL by stripping the leading
> "/tomcat".
>
> FOR Apache we use mod_rewrite for those tricks, because it is a  
> modular
> server and there exists many usefuk modules. For IIS this kind of
> ability is already build into the JK isapi plugin.
>
> Is that what you are looking for?
>
> Note that now we don't replace /tomcat by /servlet-examples, so a
> working request now would be /tomcat/servlet-example/something.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Rainer Jung <ra...@kippdata.de>.
OK, but that doesn't fit into your first mail.

So here is the proposed solution:

LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteRule /tomcat/(.*) /$1
[E=JK_WORKER_NAME:myworker,H=jakarta-servlet,PT]

The RewriteRule line extends until "PT]"

This will activate JK forwarding via a worker called myworker (you can
replace it by the name of your worker) for everything that starts with
/tomcat/ and also changes the forwarding URL by stripping the leading
"/tomcat".

FOR Apache we use mod_rewrite for those tricks, because it is a modular
server and there exists many usefuk modules. For IIS this kind of
ability is already build into the JK isapi plugin.

Is that what you are looking for?

Note that now we don't replace /tomcat by /servlet-examples, so a
working request now would be /tomcat/servlet-example/something.

Regards,

Rainer

Shug Boabby schrieb:
> On 4 Nov 2007, at 13:48, Rainer Jung wrote:
>>> To reiterate what I would like to do... I want to be able to set up
>>> http://myserver.com/tomcat to point to http://myserver.com:8180 and
>>> likewise for SSL. It surprises me that more people do not want a simple,
>>> hassle-free setup like this!
>>
>> This requirement is not well defined.
>>
>> What do you want to happen with a request like this:
>>
>> http://myserver.com/tomcat/a/b/c.d
> 
> I would like that request to go to tomcat, where tomcat sees that it
> received the request "a/b/c.d" on the myserver.com domain. The result
> would be the same as calling
> 
>   http://myserver.com:8180/a/b/c.d
> 
> directly. And similarly for SSL. I'd like to use Apache to do the SSL
> layer (as it is more efficient and saves maintaining 2 sets of
> certificates), but I still want Tomcat to know if it is communicating
> over a CONFIDENTIAL channel or not.
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Shug Boabby <sh...@gmail.com>.
On 4 Nov 2007, at 13:48, Rainer Jung wrote:
>> To reiterate what I would like to do... I want to be able to set up
>> http://myserver.com/tomcat to point to http://myserver.com:8180 and
>> likewise for SSL. It surprises me that more people do not want a  
>> simple,
>> hassle-free setup like this!
>
> This requirement is not well defined.
>
> What do you want to happen with a request like this:
>
> http://myserver.com/tomcat/a/b/c.d

I would like that request to go to tomcat, where tomcat sees that it  
received the request "a/b/c.d" on the myserver.com domain. The result  
would be the same as calling

   http://myserver.com:8180/a/b/c.d

directly. And similarly for SSL. I'd like to use Apache to do the SSL  
layer (as it is more efficient and saves maintaining 2 sets of  
certificates), but I still want Tomcat to know if it is communicating  
over a CONFIDENTIAL channel or not.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Rainer Jung <ra...@kippdata.de>.
Let's first start with what you actually want to achieve:

Shug Boabby schrieb:
> Thanks Rainer and Janning,
> 
> I'm afraid my question is still unanswered... but I am particularly
> interested in what you say here
> 
> On 4 Nov 2007, at 12:43, Rainer Jung wrote:
>> You can though deploy your webapps not on the top level directory, but
>> instead into a sub directory (using a path, that contains more than
>> one URL directory component), e.g. /tomcat/servlet-examples etc.
>> directly on your tomcat, and then JkMount /tomcat/*. That'll be true
>> zero-admin.
> 
> I have tried to do this on Tomcat 5.5. i.e. instead of deploying
> MyApp.war to /usr/share/tomcat/webapps I'm deploying to
> /usr/share/tomcat/webapps/subdir. But tomcat is not able to pick up on
> any of the war files in the subdirectory. Is that what you meant?
> 
> To reiterate what I would like to do... I want to be able to set up
> http://myserver.com/tomcat to point to http://myserver.com:8180 and
> likewise for SSL. It surprises me that more people do not want a simple,
> hassle-free setup like this!

This requirement is not well defined.

What do you want to happen with a request like this:

http://myserver.com/tomcat/a/b/c.d

Regards,

Rainer


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Rainer Jung <ra...@kippdata.de>.
Concerning webapp deployment in nested directories:

have a look at

http://tomcat.apache.org/tomcat-5.5-doc/config/context.html

Look out for the character "#" and using a *.xml deployment descriptor.

But please think about my previous question first :)

Regards,

Rainer

Shug Boabby schrieb:
> On 4 Nov 2007, at 12:43, Rainer Jung wrote:
>> You can though deploy your webapps not on the top level directory, but
>> instead into a sub directory (using a path, that contains more than
>> one URL directory component), e.g. /tomcat/servlet-examples etc.
>> directly on your tomcat, and then JkMount /tomcat/*. That'll be true
>> zero-admin.
> 
> I have tried to do this on Tomcat 5.5. i.e. instead of deploying
> MyApp.war to /usr/share/tomcat/webapps I'm deploying to
> /usr/share/tomcat/webapps/subdir. But tomcat is not able to pick up on
> any of the war files in the subdirectory. Is that what you meant?

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Shug Boabby <sh...@gmail.com>.
Thanks Rainer and Janning,

I'm afraid my question is still unanswered... but I am particularly  
interested in what you say here

On 4 Nov 2007, at 12:43, Rainer Jung wrote:
> You can though deploy your webapps not on the top level directory,  
> but instead into a sub directory (using a path, that contains more  
> than one URL directory component), e.g. /tomcat/servlet-examples  
> etc. directly on your tomcat, and then JkMount /tomcat/*. That'll be  
> true zero-admin.

I have tried to do this on Tomcat 5.5. i.e. instead of deploying  
MyApp.war to /usr/share/tomcat/webapps I'm deploying to /usr/share/ 
tomcat/webapps/subdir. But tomcat is not able to pick up on any of the  
war files in the subdirectory. Is that what you meant?

To reiterate what I would like to do... I want to be able to set up http://myserver.com/tomcat 
  to point to http://myserver.com:8180 and likewise for SSL. It  
surprises me that more people do not want a simple, hassle-free setup  
like this!

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jk_mod and binding tomcat's root to an apache directory

Posted by Rainer Jung <ra...@kippdata.de>.
Hi,

actually there are two things to discuss here:

1) How to express rules which requests should be forwarded
2) Rewriting URLs

and finally, how does one combine the two.

Concerning 1)
-------------

First the case, where you don't want to rewrite the URL, e.g. the
browser really asks for /servlet-examples-URLs directly.

Then you would simply use

JkMount /servlet-examples/* myworker

(and myworker is a placeholder for the name of your worker).

In case you want to also forward the exact URL /servlet-examples, but
e.g. not /servlet-examples2, you can combine

JkMount /servlet-examples/* myworker
JkMount /servlet-examples/ myworker

into one line:

JkMount /servlet-examples|/* myworker

Concerning 2)
-------------

You can rewrite URLs via mod_rewrite. For your example a very basic
configuration (based on httpd 2.2) would be

LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteRule /tomcat/(.*) /servlet-examples/$1

Since you want to combine the rewriting with mod_jk, i.e. mod_jk should
forward the rewritten URL, and not the original URL, you need to add the
PT flag to the rewrite rule (see mod_rewrite docs in httpd docs).

RewriteRule /tomcat/(.*) /servlet-examples/$1 [PT]

Now this will mean, that also the JkMount will be matched against the
rewritten rule.

In most cases it will be more adequate to really add JkMounts like

JkMount /servlet-examples|/* myworker

because you want to manage forwardingby the actual contexts/webapps
deployed on the backends. If you *really* want to forward based on the
original URL, you can do this in httpd 2.2 with another extension of the
rewrite rules:

RewriteRule /tomcat/(.*) /servlet-examples/$1
[E=JK_WORKER_NAME:myworker,H=jakarta-servlet,PT]

This will set the handler to jakarta-servlet, which activates JK
forwarding for this request even without any matching JkMount, and the
forwarding takes the name of the worker out of the environment variable
JK_WORKER_NAME, which we set to myworker.

Even without rewriting, the setup is zero-admin, as long as there is no
new context deployed. The exact servlets do not matter. Whenever you add
another webapp, e.g. jsp-examples, you need to add another config line,
either when using JkMount and doing no URL rewriting, or when using
Rewriting.

You can though deploy your webapps not on the top level directory, but
instead into a sub directory (using a path, that contains more than one
URL directory component), e.g. /tomcat/servlet-examples etc. directly on
your tomcat, and then JkMount /tomcat/*. That'll be true zero-admin.

I hope that's understandable :)

Regards,

Rainer

Shug Boabby schrieb:
> Hello everyone,
> 
> There does not appear to be a separate list for mod_jk discussions... so
> I assume this is the most relevant place to ask questions. Please let me
> know if there is somewhere more specific for me to bring this.
> 
> I have mod_jk up and running with Apache 2 and Tomcat 5.5. However, it
> seems that every single servlet must be mapped by hand in the apache
> config files! This seems like a lot of work to me. What I'd really like
> to do would be to map my server's "/tomcat" path to redirect any
> requests to Tomcat's root. e.g. a request coming in to my server at
> /tomcat/servlet-examples would be re-routed to Tomcat's /servlet-examples
> 
> Such a setup would mean zero admin in the Apache-Tomcat bridge when new
> servlets are added. As they are added to Tomcat, they immediately become
> accessible in Apache's /tomcat/ directory. Is it possible to set it up
> this way? It seems a very sensible way to do things.
> 
> Shug

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org