0

I'm trying to set up my java app as the main component of a new site.

I have some static resources I'd like served by Apache, so I setup Apache and Mod_jk, with the following rules,

    JkMount /java_app* ajp13
    JkUnmount /*static/* ajp13
    RewriteEngine On
    RewriteRule ^/$ /java_app/ [L,PT]

Workers file and everything is working swell. When I go to http://www.example.com/, I get the index file for my java app due to the rewrite rule. If I browse around the site, I still get my java app due to mod_jk, like http://www.example.com/java_app/view/1/.

The problem: when I head back to http://www.example.com, I completely lose any session information. If I was logged in, I'm logged out, and the links from there are getting appended with jsessionids.

How do I fix this? Is this the proper way to connect apache and tomcat, or is there a better way?

EDIT:

To respond to the first answer,

Still a bit stuck. When I load up firebug, I see this when I navigate to /

Set-Cookie JSESSIONID=8D63C9682E39B81F669E277ED07542E1; Path=/javaapp 

As I browse around inside the java app, I see that the same jsessionid stays with me - firebug says I'm sending in the request headers.

When I hit / again, I get this in the response,

Set-Cookie JSESSIONID=5DC9F39CE85AB1E71B8D87EB9D485FE9; Path=/javaapp

So I guess Apache forwards on my request without my cookie information, so Tomcat gives me a new one? Can I tell mod_rewrite to say ex. ^/$ /javaapp/;jsessionid={cookie} ?

5 Answers 5

2

Don't use mod_jk2 (which is deprecated anyway), but use mod_proxy with ProxyPass and ProxyReversePass. Much easier to configure, even your exception for static content can be expressed easily:

ProxyPass /statics !
ProxyPass / http://localhost:8080
ProxyPassReverse / http://localhost:8080

The drawback is obviously that if the Java application wants to read the client's IP address (and other client-information), it will get the Apache's address instead as he is the playing proxy. For this situations, you will need to use mod_jk

2
  • 2
    mod_jk is not deprecated. mod_jk2 is deprecated. Jan 27, 2010 at 14:59
  • You can use mod_proxy and still get the client's real IP address, etc. You will likely want to enable the RemoteIPValve and SSLValve on the Tomcat side. mod_jk is not necessary to get this information. Aug 17, 2023 at 21:12
1

I suspect it's a cookie path problem. To confirm that, you may fire up your HTTP debugger and analyse the HTTP traffic.

0
1

Set worker.worker1.sticky_session=1

I say use mod_jk, as its created especially for tomcat ajp and its well maintened ( every year thers update with new fetures)

0

Thanks both. I agree that it is a cookie path problem, or an issue with Apache not sending the cookie info forward, or something.

I ended up making the tomcat webapp ROOT, which caused the cookie path problems to go away, along with removing the /javapp context root from the URLs a nice side affect. I ended up with mod_proxy_ajp, as it was easy to configure, and I found some shibboleth documentation that pointed to this being the best option.

It seems like this whole space is such voodoo, and everybody comes up with their own solution, that I might as well find something that works and just run with it...

1
  • 1
    can you post your final solution for those interested?
    – brad
    Jun 30, 2010 at 15:35
0

You can accomplish this using mod_header in your config which has functionality similar mod_rewrite but is used for modifying http headers.

To change all cookie paths from /javaapp to /

Header edit Set-Cookie "^(.*; Path=)/javaapp/?(.*)" $1/$2

Or if you wanted to change the cookie path entirely from /javaapp to say /my_java_app

Header edit Set-Cookie "^(.*; Path=)/javaapp/?(.*)" $1/my_java_app/$2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .