You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Brendan Colthurst <br...@inertiabev.com> on 2004/10/22 02:27:59 UTC

Session Cookie problem with Apache, Tomcat, mod_jk, mod_rewrite.

I apologize if this is the wrong list, but I think it should be the right
one.

Tomcat writes session cookies with the webapp name in the cookie's path
field, but I map URLs by domain to hide the webapp name, with mod_rewrite.
So my sessions ain't stickin', 'cause the browser does not know to send up
the cookie.

The problem:  Sessions won't take hold, because I use mod_rewrite in Apache
to change http://www.domain.com/ to http://www.domain.com/webapp without
redirection, before sending it off through mod_jk to tomcat on another
server.

Now, that being said, I have sessions working when I use
http://www.domain.com/webapp/ explicitly and configure things to leverage
that.  But I want to hide the webapp subdir from the browsing experience.

I run multiple sites, and each site has a webapp on my tomcat machine, which
has one instance of tomcat running.

End desired goal:
A) www.domain.com in user's browser.
B) multiple webapps in ONE tomcat instance, to reduce memory usage.  I want
to avoid separate tomcat instances for each website.
C) Sessions that work with www.domain.com in the browser. [i.e. no webapp
sub-dir name]
D) Use Apache, mod_jk and Tomcat.  And mod_rewrite where needed.

My setup:
Apache: 1.3.27 
Tomcat: 4.1.27

Example of how I have apache virtual hosts setup:

<VirtualHost [ipaddresshere]:80>
RewriteEngine on

ServerName www.domain.com

ServerAdmin myemail@domain.com
DocumentRoot /home/appman/sites

ErrorLog logs/domain_error.log
CustomLog logs/domain_access.log combined

#rewrites URLS for directories to webapp with index.jsp
RewriteRule ^(.*)/$ /webappname$1/index.jsp [NS,PT,L]

#rewrites plain www.domain.com  to the webapp homepage jsp
RewriteRule ^$ /webappname/index.jsp [NS,PT,L]

#rewrites all explicit jsp file requests to have webappname.
RewriteRule   ^(.*) /webappname$1 [NS,PT,L]

#all modrewrites use pass-through and Last, to avoid explicit redirect, and
to only rewrite once.
#it then goes to mod_jk

JkMount /* server4

</VirtualHost>

* * * *
My server.xml file, below the connectors:

      <Host name="www.generaldomainofappserver.com" debug="0"
appBase="webapps"
       unpackWARs="true" autoDeploy="true">
 <Alias>www.domain.com</Alias>
 <Alias>www.domain2.com</Alias>
<!-- ... About 20 domains aliased here, one for each site I'm running -->

<Context path="/webappname" docBase="webappname" debug="0"></Context>
<Context path="/webappnametwo" docBase="webappnametwo" debug="0"></Context>

<!-- ... About 20 webapps listed here, one for each site I'm running -->
      </Host>


* * * * 
workers.properties:

worker.server4.type=ajp13
worker.server4.lbfactor=1
worker.server4.port=MODJKCONNECTORPORT
worker.server4.host=IP_OF_TOMCAT_MACHINE
worker.server4.socket_keepalive=1
worker.server4.cachesize=20
worker.server4.cache_timeout=600

So, my questions: 

1) Can I get around this by having multiple "Host" descriptors in my
server.xml, one for each domain, and having each one use a context
descriptor like:
<Context path="/" docBase="webappname"></Context>

in effect, making each webapp its own root webapp?

I tried that out, but it didn't deploy correctly.  Perhaps because the two
HOST descriptors I used had the same appBase, "webapps"?  Perhaps the
autoDeploy was double deploying the webapp to both Hosts, causing trouble?

Could I put each site's "appBase" into its own folder, and would that solve
the problem?

I've searched the archives for information on this to no avail.  Of course
perhaps I was searching on the wrong terms...

I've also investigated modifying the Tomcat source code, specifically around
line 618 in org.apache.catalina.connector.HttpResponseBase.java , to get rid
of anything that says, when writing a session cookie, "
cookie.setPath(contextPath);" --- and just have it set it as  "
cookie.setPath("/");  ".  I tried that, but there may be other classes
involved in session cookie setting, because my session cookies still came up
on my browser as having the "/webappname" as the cookie path...  Perhaps the
jk connector java code needs to be modified, too?  Could it be that Apache,
after having re-written the url to have the webapp name, makes the cookies
being set keep that sub-dir?  I'm ignorant about how cookies get passed back
through the chain from Tomcat, to mod_jk, to Apache and to the browser.  I'm
working with the assumption that only Tomcat is really involved, and it's
just more response header data being sent back -- ideally mod_jk and apache
shouldn't care about how I set the cookies...

Thanks so much for your help -- let me know if I can be of assistance in
return -- I'm willing to trade services or trouble-shooting advice for
someone who can help solve this for me, for what its worth.

Thanks!
-Brendan



 





---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Multiple Hosts, multiple Root apps, path="/" -- Is it possible?

Posted by Brendan Colthurst <br...@inertiabev.com>.
Can I setup my server.xml to have multiple "root" webapps, each with
path="/" in its Context tag, if I use multiple Host descriptors?

Has anyone done this who could share some server.xml configuration code?

I mostly want to do this so that my session cookies don't have to have the
webapp name in them...

Thanks,
Brendan


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: jdbc pool

Posted by Viorel Dragomir <vd...@wylog.com>.
Follow 
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html#Database%20Connection%20Pool%20(DBCP)%20Configurations 
closely.




Viorel Dragomir

.
..
-------------------------------------------------------------------
vioss was here


----- Original Message ----- 
From: kangkoong Kakoong 
To: Tomcat Users List 
Sent: Friday, October 22, 2004 10:52
Subject: jdbc pool


when I compile using jdbc pool the following error
show:

javax.servlet.ServletException: Name jdbc is not bound
in this Context
VerifyLogin.doPost(Unknown Source)

javax.servlet.http.HttpServlet.service(HttpServlet.java:763)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

javax.naming.NameNotFoundException: Name jdbc is not
bound in this Context

org.apache.naming.NamingContext.lookup(NamingContext.java:815)

org.apache.naming.NamingContext.lookup(NamingContext.java:185)

org.apache.naming.NamingContext.lookup(NamingContext.java:826)

org.apache.naming.NamingContext.lookup(NamingContext.java:185)

org.apache.naming.NamingContext.lookup(NamingContext.java:826)

org.apache.naming.NamingContext.lookup(NamingContext.java:198)

org.apache.naming.SelectorContext.lookup(SelectorContext.java:183)

javax.naming.InitialContext.lookup(InitialContext.java:347)
VerifyLogin.doPost(Unknown Source)

javax.servlet.http.HttpServlet.service(HttpServlet.java:763)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

What is that mind?

Thanks in advance



_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

jdbc pool

Posted by kangkoong Kakoong <ka...@yahoo.com>.
when I compile using jdbc pool the following error
show:

javax.servlet.ServletException: Name jdbc is not bound
in this Context
	VerifyLogin.doPost(Unknown Source)

javax.servlet.http.HttpServlet.service(HttpServlet.java:763)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

javax.naming.NameNotFoundException: Name jdbc is not
bound in this Context

org.apache.naming.NamingContext.lookup(NamingContext.java:815)

org.apache.naming.NamingContext.lookup(NamingContext.java:185)

org.apache.naming.NamingContext.lookup(NamingContext.java:826)

org.apache.naming.NamingContext.lookup(NamingContext.java:185)

org.apache.naming.NamingContext.lookup(NamingContext.java:826)

org.apache.naming.NamingContext.lookup(NamingContext.java:198)

org.apache.naming.SelectorContext.lookup(SelectorContext.java:183)

javax.naming.InitialContext.lookup(InitialContext.java:347)
	VerifyLogin.doPost(Unknown Source)

javax.servlet.http.HttpServlet.service(HttpServlet.java:763)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

What is that mind?

Thanks in advance


		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org