webForumDet fria alternativet

mod_jk2, Apache, Tomcat

6 svar · 282 visningar · startad av Viktor

ViktorMedlem sedan aug. 20021 752 inlägg
#1

Har fått igång mod_jk2 nu så att även anropp som ska till Tomcat (Java server) kan skickas via Apache transparant för användaren. Problemet är bara att jag får det bara att fungera om jag skickar över en hel domän,

[uri:https://www.vgsoftware.com/*]
worker=ajp13:localhost:8009

denna kod skickar altså alla anropp till denna domän till tomcat, bilder, html osv. Men hur gör jag så att bara jsp och servlets skickas till tomcat? Jag har provat med *.jsp men får det inte att fungera.

/Viktor

nicclasMedlem sedan feb. 20001 050 inlägg
#2

Jag kör Apache2 och mod_jk2 och har
<Location "/demo/*.jsp">
JkUriSet worker ajp13:localhost:8009
</Location>
i min httpd.conf men har kommenterat bort min "URI mapping" i min workers2.properties, och det fungerar. Prova?

Aleph_OneMedlem sedan juni 2003372 inlägg
#3

Jag gör så här för att skicka jsp och servlets till tomcat:
Då spelar det mindre roll var jsp filerna ligger, men alla mina servlets anropas genom /servlet/foo

i workers2.properties

# socket channel
[channel.socket:localhost:8009]
port=8009
host=127.0.0.1                                                                                                                                                                                

# worker for the connector
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009                                                                                                                                                                                

[uri:[url]www.domän.com:80/*.jsp[/url]]
worker=ajp13:localhost:8009                                                                                                                                                                                

[uri:[url]www.domän.com:80/servlet/*[/url]]
worker=ajp13:localhost:8009

och för att index.jsp sen ska hittas också så har jag lagt med den i httpd.conf DirectoryIndex ... index.jsp
Jag kör med apache 2 mod_jk2 och Tomcat 5..

Om jag inte kommer ihåg fel så läste jag för ett tag sen att mappningarna ska man helst göra i workers2.properties och inte i httpd.conf pga av problem med delat minne. Ska se om jag hittar den artikeln igen.

nicclasMedlem sedan feb. 20001 050 inlägg
#4

Om jag inte kommer ihåg fel så läste jag för ett tag sen att mappningarna ska man helst göra i workers2.properties och inte i httpd.conf pga av problem med delat minne. Ska se om jag hittar den artikeln igen.

Jag har troligen provat att använda workers2.properties och inte fått det att fungera som jag vill - sedan provade jag det jag skrev ovan och det fungerade, och sen har jag inte funderat mer över det... Tills du nu nämner att det skulle kunna vara sämre...

Jag kände mig tvungen att kolla upp detta ;)

I källkoden till mod_jk2 (dvs, mod_jk2.c som finns på apache.org sajten) så står det dock:
/**
* Set a property associated with a URI, using native <Location>
* directives.
*
* This is used if you want to use the native mapping and
* integrate better into apache.
*
* Same behavior can be achieved by using uri.properties and/or JkSet.
*
* Example:
* <VirtualHost foo.com>
* <Location /examples>
* JkUriSet worker ajp13
* </Location>
* </VirtualHost>
*
* This is the best way to define a webapplication in apache. It is
* scalable ( using apache native optimizations, you can have hundreds
* of hosts and thousands of webapplications ), 'natural' to any
* apache user.
*
* XXX This is a special configuration, for most users just use
* the properties files.
*/
vilket gör att jag tror att jag behåller det som det är :)

Då har vi rett ut detta, men kanske löser det inte Viktors problem?

Aleph_OneMedlem sedan juni 2003372 inlägg
#5

Jo jag har också varit inne och nosat i källkoden tidigare ;)
Men vad det än står där så hindrar det inte att diverse andra problem kan dyka upp.

Här är ett utdrag som beskriver problemet:

http://www.aexx.net/arcane/article.jsp?article=tomcat4-apache2-jk2 (punkt 13) skrev:

One would hope that a simple extension of the technique presented in the previous section would allow us to deploy web applications inside of Apache <VirtualHost> directives. Unfortunately, this is not the case as far as I have been able to determine. It would appear that specifying a <Location> inside of a <VirtualHost> will cause all of the VirtualHosts that don't explicitly override that location to suddenly begin using mod_jk2! If you're trying to give one virtual host access to Tomcat, you will inadvertently give all of them access (or, perhaps worse, you may suddenly cause one person's content to appear to be another person's content - it gets pretty nasty).

So, the way around this is to revert to using workers2.properties. It's kind of entertaining, because the official mod_jk2 documentation on the Apache website actually has a comment in it suggesting that all of the entries in workers2.properties get moved to httpd.conf, particularly for virtual hosts. Drat!

Let's say that I want only https://www.aexx.net to have access to the tomcat-docs webapp. Well, what I need to do is make the following entry in my workers2.properties (altered lines in red):

# Define the communication channel [channel.socket:localhost:8009] tomcatId=localhost:8009 [ajp13:localhost:8009] channel=channel.socket:localhost:8009 #[uri:/examples/*] #worker=ajp13:localhost:8009 [uri:https://www.aexx.net/docs/*] worker=ajp13:localhost:8009

This will restrict the allowable URLs to only those that start with www.aexx.net. Don't forget to comment-out or delete the <Location> tag in httpd.conf:

# <Location "/docs/*"> # JkUriSet worker ajp13:localhost:8009 # </Location>

The logical extension of this is to add one such entry for each virtual host you plan to give access to. If you find a better way to do this, I would really love to hear about it - please use the link at the bottom of this article to send me a message!

Här några länkar som beskriver dom problem som finns och har funnits med JkUriSet.

http://www.aexx.net/arcane/article.jsp?article=tomcat4-apache2-jk2 (punkt 13)

http://hopdev.helma.org/doczone/mod+jk2/ (Note längst ner)

"mod_jk2 doesn't handle vhosts correctly when using the JkUriSet commands"
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18472

"mod_jk2 2.0.4 does not work with existing configuration"
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=28016

"JkUriSet does not set the hostname"
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18569

Jag tycker att det bästa hade varit om man gjorde all konfiguration i httpd.conf med Apaches utmärkta syntax, men än så länge verkar det finnas rejäla buggar kvar så jag håller mig till workers2.properties till nästa bugfix av mod_jk2 iaf. :)

nicclasMedlem sedan feb. 20001 050 inlägg
#6

Du har så rätt så Aleph_One! Det blir problem när jag kör med flera domän mot samma server och jag använder <Location>-sättet i httpd.conf. Det hade jag inte noterat förut, men när jag provar så ser jag att så är fallet. Det verkar dock inte som om webbsidor för "fel domän" visas, men något skumt händer för Apache "låser sig" och säger inte "Object not found" direkt vilket den borde. Men att flytta UriSet/uri: till en workers2.properties verkade (nu) fungera bra. Kanske var det en JkSet, för att sätta korrekt sökväg till workers2-filen, som saknades förra gången jag provade.

ViktorMedlem sedan aug. 20021 752 inlägg
#7

Tack för svaren, fick det att fungera nu :)

/Viktor

132 ms totalt · 3 externa anrop · v20260731065814-full.86db40fa
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
128 ms — hämta tråd, inlägg och bilagor (db)